A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2016 Set 1 · Q10
Time
Select one answerSingle correct
Solution
Official answer: A) Both operations can be performed in O(1) time
Linear Structures, Trees and HeapsA queue can be efficiently implemented using a circular array with two pointers, front and rear.
ENQUEUE operation: Increments the rear pointer using modulo arithmetic (rear = (rear + 1) % capacity) and inserts the element at array[rear]. This takes $O(1)$ time.
DEQUEUE operation: Removes the element at array[front] and increments the front pointer using modulo arithmetic (front = (front + 1) % capacity). This also takes $O(1)$ time.
Since both operations perform a constant number of operations without shifting remaining elements, both ENQUEUE and DEQUEUE run in time.
Therefore, option A is correct.
Try the question first, then check your work.
Examiner trap
Think about circular array implementation of queues using front and rear pointers.
This Linear Structures, Trees and Heaps previous year question is Q10 of the GATE CSE 2016 Set 1 paper. Find more GATE CSE PYQs on Linear Structures, Trees and Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Linear Structures, Trees and Heaps PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Linear Structures, Trees and Heaps has 14 GATE CSE PYQs across 12 papers from 2012 to 2026. 7 of them are 1-mark MCQs like this one, and GATE CSE 2016 Set 1 has 2.
How GATE tests Linear Structures, Trees and HeapsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.