Introduction to Queue Data Structure (original) (raw)

Last Updated : 28 Mar, 2025

**Queue is a linear data structure that follows FIFO (First In First Out) Principle, so the first element inserted is the first to be popped out.

**FIFO Principle in Queue:

FIFO Principle states that the first element added to the Queue will be the first one to be removed or processed. So, Queue is like a line of people waiting to purchase tickets, where the first person in line is the first person served. (i.e. First Come First Serve).

FIFO-Principle-First-In-First-Out-1

Basic Terminologies of Queue

**Representation of Queue

Representation-of-Queue-Data-Structure

**Queue Operations

  1. **Enqueue: Adds an element to the end (rear) of the queue. If the queue is full, an overflow error occurs.
  2. **Dequeue: Removes the element from the front of the queue. If the queue is empty, an underflow error occurs.
  3. **Peek/Front: Returns the element at the front without removing it.
  4. **Size: Returns the number of elements in the queue.
  5. **isEmpty: Returns true if the queue is empty, otherwise false.
  6. **isFull: Returns true if the queue is full, otherwise false.

For detailed steps and more information on each operation, Read Basic Operations for Queue in Data Structure.

Implementation of Queue Data Structure

Queue can be implemented using following data structures:

Complexity Analysis of Operations on Queue

Operations Time Complexity Space Complexity
enqueue O(1) O(1)
dequeue O(1) O(1)
front O(1) O(1)
size O(1) O(1)
isEmpty O(1) O(1)
isFull O(1) O(1)

**Types of Queues

Queue data structure can be classified into 4 types:

  1. **Simple Queue: Simple Queue simply follows **FIFO Structure. We can only insert the element at the back and remove the element from the front of the queue. A simple queue is efficiently implemented either using a linked list or a circular array.
  2. **Double-Ended Queue (Deque): In a double-ended queue the insertion and deletion operations, both can be performed from both ends. They are of two types:
    • **Input Restricted Queue: This is a simple queue. In this type of queue, the input can be taken from only one end but deletion can be done from any of the ends.
    • **Output Restricted Queue: This is also a simple queue. In this type of queue, the input can be taken from both ends but deletion can be done from only one end.
  3. **Priority Queue: A priority queue is a special queue where the elements are accessed based on the priority assigned to them. They are of two types:

Types-of-Queue

types of queues

**Applications of Queue Data Structure

Application of queue is common. In a computer system, there may be queues of tasks waiting for the printer, for access to disk storage, or even in a time-sharing system, for use of the CPU. Within a single program, there may be multiple requests to be kept in a queue, or one task may create other tasks, which must be done in turn by keeping them in a queue.

Please refer Applications of Queue for more details.

Similar Reads

Queue implementation in different languages












Easy problems on Queue








Intermediate problems on Queue