Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Interview Problems on Queue
  • Practice Queue
  • MCQs on Queue
  • Queue Tutorial
  • Operations
  • Applications
  • Implementation
  • Stack vs Queue
  • Types of Queue
  • Circular Queue
  • Deque
  • Priority Queue
  • Stack using Queue
  • Advantages & Disadvantages
Open In App
Next Article:
FIFO Principle of Queue
Next article icon

FIFO Principle of Queue

Last Updated : 28 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

FIFO stands for "First In, First Out". This principle dictates that the first element added to the queue is the first one to be removed. Understanding the FIFO principle is crucial for anyone working in computer science, especially when dealing with queues.

It ensures that the first task or item you add to the queue is the first to be processed or removed. Whether you're printing documents, managing tasks, or simulating real-world scenarios, FIFO helps maintain order and fairness.

In Queue Data Structure FIFO has two major operations, Let's break it down:

Enqueue

When you add an element to the end of the queue, it's called "enqueuing" that element. This is similar to a person joining the back of the line.

Dequeue

When you remove an element from the front of the queue, it's called "dequeuing" that element. This is akin to the first person in line being served and leaving.

Why FIFO is Important

FIFO is crucial for many real-life and computer-based scenarios:

Simulating Real-Life Scenarios

  • In the real world, queues are everywhere - from standing in line at a grocery store to handling customer service requests. FIFO helps us mimic these real-life situations in computer programs.

Print Queue

  • Imagine multiple documents to be printed. The first document sent to the printer should be the first one to come out. This is where FIFO ensures fairness.

Task Scheduling

  • In an operating system, when many tasks are competing for resources, FIFO helps manage who gets CPU time first, ensuring fairness and efficiency.

Example of FIFO in a Queue

Let's illustrate FIFO with a simple example:

  1. Start with an empty queue.
  2. We enqueue elements A, B, and C in that order.
    • Queue: A, B, C
  3. Now, let's dequeue an element. As per FIFO, we remove A, the first one added.
    • Queue: B, C
  4. Next, we enqueue D.
    • Queue: B, C, D
  5. Dequeue again, and B is the one to go.
    • Queue: C, D

So, just like standing in line at your favourite coffee shop, remember that the first in line is the first to be served when you encounter queues in your programming journey.

To learn about Queue follow this link!!


Next Article
FIFO Principle of Queue

S

srinam
Improve
Article Tags :
  • Queue
  • DSA
Practice Tags :
  • Queue

Similar Reads

    Applications of Priority Queue
    A Priority Queue is different from a normal queue, because instead of being a "first-in-first-out", values come out in order by priority. It is an abstract data type that captures the idea of a container whose elements have "priorities" attached to them. An element of highest priority always appears
    2 min read
    Queue in Go Language
    A queue is a linear structure that follows a particular order in which the operations are performed. The order is First In First Out (FIFO). Now if you are familiar with other programming languages like C++, Java, and Python then there are inbuilt queue libraries that can be used for the implementat
    4 min read
    Queue in C
    A queue is a linear data structure that follows the First In First Out (FIFO) order of insertion and deletion. It means that the element that is inserted first will be the first one to be removed and the element that is inserted last will be removed at last.In this article, we'll learn how to implem
    7 min read
    Frequency in Queue
    We need to implement findFrequncy(k) operation for a queue along with normal enqueue() operation. The findFrequency(k) function should return frequency of item k in queue.Given an empty queue and two arrays, the task is to insert elements of the first array into a queue and find frequencies of the i
    5 min read
    Perl | Implementing a Queue
    Prerequisite: StackQueue in Perl is a linear abstract data structure which follows the FIFO (First In First Out) order. It resembles the properties of the queue which we encounter in our daily life where the person who comes first will be served first. It is open at both ends. Unlike stack where the
    10 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences