Introduction to Queues

A queue is a linear data structure that follows the principle:

FIFO – First In, First Out

Think of a line at a ticket counter 

  • The person who comes first is served first

  • New people join at the rear

  • Service happens from the front


Basic Terms

  • Front – Position from where elements are removed

  • Rear – Position where elements are inserted


Basic Operations on Queue

  1. Enqueue – Insert an element at the rear

  2. Dequeue – Remove an element from the front

  3. Peek / Front – View the front element

  4. isEmpty – Check if the queue is empty

  5. isFull – Check if the queue is full (array implementation)


Simple Example

Enqueue(10)
Enqueue(20)
Enqueue(30)

Queue:

Front → 10  20  30 ← Rear

Dequeue() → removes 10

 

Queue becomes:

Front20 30Rear


Queue Representation

Queues can be implemented using:

  • Arrays

  • Linked Lists

Special types of queues:

  • Circular Queue

  • Priority Queue

  • Deque (Double-ended Queue)


Applications of Queue

Queues are used in many real-life and computer applications:

  • CPU scheduling

  • Printer spooling

  • Breadth First Search (BFS)

  • Call center systems

  • Data buffering (keyboard, network)


Advantages

  • Simple and efficient

  • Maintains order of data

  • Insertion and deletion are O(1) operations


Disadvantages

  • No random access

  • Fixed size problem in array-based queues

You have completed 0% of the lesson
0%