FIFO is an abbreviation for first in, first out. It is a method for handling data structures where the first element is processed first and the newest element is processed last.
Real life example:
In this example, following things are to be considered:
- There is a ticket counter where people come, take tickets and go.
- People enter a line (queue) to get to the Ticket Counter in an organized manner.
- The person to enter the queue first, will get the ticket first and leave the queue.
- The person entering the queue next will get the ticket after the person in front of him
- In this way, the person entering the queue last will the tickets last
- Therefore, the First person to enter the queue gets the ticket first and the Last person to enter the queue gets the ticket last.
This is known as First-In-First-Out approach or FIFO.
Where is FIFO used:
- Data Structures
Certain data structures like Queue and other variants of Queue uses FIFO approach for processing data.
- Disk scheduling
Disk controllers can use the FIFO as a disk scheduling algorithm to determine the order in which to service disk I/O requests.
- Communications and networking
Communication network bridges, switches and routers used in computer networks use FIFOs to hold data packets en route to their next destination.
Program Examples for FIFO
Program 1: Queue
Elements of queue-[0, 1, 2, 3, 4] removed element-0 [1, 2, 3, 4] head of queue-1 Size of queue-4
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- FIFO vs LIFO approach in Programming
- Program for Page Replacement Algorithms | Set 2 (FIFO)
- Queue based approach for first non-repeating character in a stream
- Iterative approach to check if a Binary Tree is Perfect
- What is Competitive Programming and How to Prepare for It?
- Shortest path in a complement graph
- Count of prime factors of N to be added at each step to convert N to M
- Minimum nodes to be colored in a Graph such that every node has a colored neighbour
- Count of elements on the left which are divisible by current element | Set 2
- Count of triplets in an Array (i, j, k) such that i < j < k and a[k] < a[i] < a[j]
- Check if it is possible to reach to the index with value K when start index is given
- Print sublist of a given Linked List specified by given indices
- Comparison between Lists and Array in Python
- Check if the end of the Array can be reached from a given position
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.