Open In App

FIFO Principle of Queue

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

Print Queue

Task Scheduling

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!!

Article Tags :