Photo AI

Last Updated Sep 27, 2025

Queues Simplified Revision Notes

Revision notes with simplified explanations to understand Queues quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

256+ students studying

Queues

Overview

A queue is a linear data structure that stores data in a First-In, First-Out (FIFO) order. This means the first item added to the queue is the first one to be removed. Queues are commonly used in scenarios where order matters, such as task scheduling, managing print jobs, or simulating real-world lines.

Structure of a Queue

A queue supports two primary operations:

  1. Enqueue: Adds an element to the back of the queue.
  2. Dequeue: Removes and returns the element from the front of the queue. Other useful operations include:
  • Peek: Retrieves the front element without removing it.
  • isEmpty: Checks if the queue is empty.
  • isFull (optional in fixed-size implementations): Checks if the queue has reached its capacity.

Types of Queues

  • Simple Queue: Basic FIFO structure.
  • Circular Queue: Connects the end of the queue back to the beginning, efficiently using available space.
  • Priority Queue: Elements are dequeued based on priority rather than order.
  • Deque (Double-Ended Queue): Allows insertion and deletion at both ends.

Implementing a Queue

Using Arrays (Procedural Approach)

  1. Enqueue Operation:
  • Check if the queue is full (optional for dynamic arrays).
  • Increment the rear pointer.
  • Insert the new element at the rear index.
  1. Dequeue Operation:
  • Check if the queue is empty.
  • Retrieve the element at the front index.
  • Increment the front pointer.
infoNote

Pseudocode Example:

# Simple Queue using a fixed-size array

MAX_SIZE = 10
queue = [None] * MAX_SIZE
front = 0
rear = -1
size = 0

def enqueue(element):
    global rear, size
    if size == MAX_SIZE:
        print("Queue Overflow")
        return
    rear = (rear + 1) % MAX_SIZE  # Circular increment
    queue[rear] = element
    size += 1

def dequeue():
    global front, size
    if size == 0:
        print("Queue Underflow")
        return None
    element = queue[front]
    front = (front + 1) % MAX_SIZE  # Circular increment
    size -= 1
    return element

Using Linked Lists (Alternative Data Structure)

In a linked list implementation:

  • Enqueue: Create a new node and link it at the end.
  • Dequeue: Remove the node from the front and update the front pointer.

Using Object-Oriented Programming (OOP)

lightbulbExample

Example in Python:

class Queue:
    def __init__(self):
        self.items = []

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

    def dequeue(self):
        if self.is_empty():
            return "Queue Underflow"
        return self.items.pop(0)

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

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

Examples

infoNote

Using a Queue to Simulate a Print Queue:

def simulate_print_queue(documents):
    queue = Queue()
    for doc in documents:
        queue.enqueue(doc)
    while not queue.is_empty():
        print(f"Printing: {queue.dequeue()}")

infoNote

Circular Queue Implementation:

class CircularQueue:
    def __init__(self, capacity):
        self.queue = [None] * capacity
        self.front = 0
        self.rear = -1
        self.size = 0
        self.capacity = capacity

    def enqueue(self, item):
        if self.size == self.capacity:
            return "Queue Overflow"
        self.rear = (self.rear + 1) % self.capacity
        self.queue[self.rear] = item
        self.size += 1

    def dequeue(self):
        if self.size == 0:
            return "Queue Underflow"
        item = self.queue[self.front]
        self.front = (self.front + 1) % self.capacity
        self.size -= 1
        return item

Note Summary

infoNote

Common Mistakes

  1. Not Handling Underflow/Overflow:
  • Forgetting to check if the queue is empty before dequeuing or peeking.
  • In fixed-size implementations, failing to handle overflow when enqueuing.
  1. Index Mismanagement in Circular Queues:
  • Incorrectly updating front or rear pointers in circular queues.
  1. Confusing LIFO with FIFO:
  • Mistaking a queue for a stack. Remember that queues operate on a First-In, First-Out basis.
infoNote

Key Takeaways

  • A queue is a FIFO data structure with key operations: enqueue, dequeue, and peek.
  • Queues can be implemented using arrays, linked lists, or classes in OOP.
  • Understand the principles of implementation rather than memorizing specific code patterns.
  • Practice implementing and tracing queues to strengthen your grasp of their behaviour in different contexts.
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Queues

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

90 flashcards

Flashcards on Queues

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

9 quizzes

Quizzes on Queues

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

29 questions

Exam questions on Queues

Boost your confidence with real exam questions.

Try Computer Science Questions

27 exams created

Exam Builder on Queues

Create custom exams across topics for better practice!

Try Computer Science exam builder

12 papers

Past Papers on Queues

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Queues you should explore

Discover More Revision Notes Related to Queues to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Data Structures

Arrays

user avatar
user avatar
user avatar
user avatar
user avatar

420+ studying

185KViews

96%

114 rated

Data Structures

Records, Lists & Tuples

user avatar
user avatar
user avatar
user avatar
user avatar

322+ studying

196KViews

96%

114 rated

Data Structures

Linked Lists

user avatar
user avatar
user avatar
user avatar
user avatar

432+ studying

185KViews

96%

114 rated

Data Structures

Stacks

user avatar
user avatar
user avatar
user avatar
user avatar

380+ studying

193KViews
Load more notes

Join 500,000+ A-Level students using SimpleStudy...

Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered