PadhaikoAll subjects

Past exam question: 2077 Chaitra (Regular), Q3

Data Structure and Algorithms · 8 marks

Open in the Padhaiko app

Topic: Queues

Question

What is queue? What are different operations that can be performed over queue?

Solution

Definition of Queue: A queue is an ordered linear data structure governed by the First-In, First-Out (FIFO) policy: new items are inserted strictly at the rear end, and existing items are removed strictly from the front end.

Fundamental Queue Operations:

  1. init(Q) / create(): Initializes an empty queue (front = 0, rear = -1 or front = rear = -1).
  2. isEmpty(Q): Returns true if no elements remain in the queue (used to guard against underflow).
  3. isFull(Q): Returns true when fixed-size storage cannot accept more items (used to guard against overflow).
  4. enqueue(Q, x): Checks for overflow; increments rear (wrapping modulo MAX in circular queues) and inserts x at Q[rear].
  5. dequeue(Q): Checks for underflow; reads Q[front], advances front, and returns the removed item.
  6. peek(Q) / front(Q): Returns Q[front] without removing it.
  7. traverse(Q) / display(Q): Visits all items sequentially from front to rear.
Answer:

A queue is a FIFO linear data structure (enqueue at rear, dequeue at front). Its core operations are init, isEmpty, isFull, enqueue (insert at rear), dequeue (remove from front), peek (inspect front), and traverse.

All past exam questions for Data Structure and Algorithms