PadhaikoAll subjects

Past exam question: 2074 Bhadra (Regular), Q3

Data Structure and Algorithms · 5 marks

Open in the Padhaiko app

Topic: Queues

Question

Define queue. Explain enqueue and dequeue operation with example.

Solution

Definition of Queue: A queue is a linear First-In, First-Out (FIFO) data structure in which additions happen at the rear and removals happen at the front.

Enqueue and Dequeue Operations with Example (MAX = 4):

Example: Starting empty (front = -1, rear = -1):

  1. enqueue(10) [10] (front=0, rear=0)
  2. enqueue(20) [10, 20] (front=0, rear=1)
  3. enqueue(30) [10, 20, 30] (front=0, rear=2)
  4. dequeue() removes 10, leaving [20, 30] (front=1, rear=2).
Answer:

A queue is a FIFO structure where enqueue(x) inserts at rear and dequeue() removes from front. Enqueuing 10, 20, 30 and dequeuing once leaves [20, 30] with 10 returned first.

All past exam questions for Data Structure and Algorithms