Back to Course
Queues

Queue in Data Structure — Types & Algorithms (with Examples)

A Queue is a linear data structure that follows the FIFO (First In, First Out) principle: the first element added is the first one removed.

Core Operations

  • enqueue(item) — insert an element at the rear.
  • dequeue() — remove and return the element at the front.
  • peek() — view the front element without removing it.
  • isEmpty() — check whether the queue has any elements.

Types of Queues

TypeDescription
Simple QueueBasic FIFO queue, insert at rear, remove from front.
Circular QueueRear wraps back to the front to reuse freed space.
Priority QueueElements are served according to priority, not order of arrival.
DequeInsertion and removal allowed at both ends.
from collections import deque

class Queue:
    def __init__(self):
        self.items = deque()

    def enqueue(self, item):
        self.items.append(item)

    def dequeue(self):
        return self.items.popleft()

    def peek(self):
        return self.items[0]

    def is_empty(self):
        return len(self.items) == 0

Complexity

OperationTime
EnqueueO(1)
DequeueO(1)
PeekO(1)

Applications

  • Task and process scheduling in operating systems.
  • Breadth First Search traversal in graphs.
  • Handling of asynchronous data such as I/O buffers and print queues.

Ready to master Data Structures & Algorithms?

Learn DSA hands-on with mentor-led sessions, real interview practice, and placement support.

Explore Course