FIFO transit lab

Queue Visualizer

Load capsules at the rear gate, serve them at the front gate, and watch First In, First Out movement.

Transit console

New values enter at REAR; removals leave from FRONT.

Transit line ready

Enqueuing while full triggers the transit overflow alarm.

Front gate operations

Line telemetry

Size

5

Front

36

Rear

13

5/8 slots occupied

Queue Visualizer

FIFO transit tube

REAR loading → FRONT service

front 36rear 13reserved 3
Drag to orbit · Scroll to zoom

What is a Queue?

A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. This means that the first element added to the queue will be the first one to be removed. It is similar to a real-life line of people waiting for a ticket; the person who arrives first gets served first.

Time Complexity

  • Enqueue (Insertion)O(1)
  • Dequeue (Deletion)O(1)
  • Peek (Front Item)O(1)
  • SearchO(n)

Real-World Applications

  • Task SchedulingOperating systems use queues to manage processes waiting for CPU time.
  • Breadth-First Search (BFS)Queues are essential for graph traversal algorithms like BFS to explore neighbors layer by layer.
  • PrintersPrint jobs are stored in a queue and processed in the order they were received.

Queue Complete Info Card

FIFO PrincipleFirst-In-First-Out

Queues follow the First-In-First-Out (FIFO) principle where the first element added is the first one to be removed. They are essential for scenarios requiring ordered processing like task scheduling and BFS.

Queue Operations

Enqueue

Add element to rear

O(1)

Dequeue

Remove element from front

O(1)

Front/Peek

View front element

O(1)

isEmpty

Check if queue is empty

O(1)

isFull

Check if queue is full (bounded)

O(1)

Size

Get number of elements

O(1)

Implementation Options

Array (Circular Buffer)

Cache-friendly, efficient
Fixed size (unless dynamic)

Linked List

Dynamic size
Extra memory for pointers

Priority Queue

Elements with priority
O(log n) enqueue/dequeue

Queue Variations

Double-Ended Queue (Deque)

Insert/remove from both ends

Priority Queue

Highest priority served first

Circular Queue

Reuses empty spaces in array

Blocking Queue

Thread-safe with wait/signal

Real-World Applications

Task Scheduling

CPU/disk scheduling algorithms

Breadth-First Search

Graph traversal algorithm

Print Queue

Managing print jobs

Message Queues

Inter-process communication

Buffering

IO streams and pipes

Ticket Counter

First-come-first-served systems

Advantages

  • Order preservation (FIFO guarantee)
  • Efficient operations (all O(1) in basic implementations)
  • Fair processing (first-come-first-served)

Limitations

  • Limited access (only front/rear elements available)
  • Fixed capacity for array implementations
  • Not versatile for random access needs
Pro Tip: Use circular queue implementation with arrays to efficiently reuse empty spaces when elements are dequeued.
FIFOO(1) operationsTask scheduling