GATE / CS ARCHIVE

GATE CSE 2016 SET 1 / QUESTION 10

GATE CSE 2016 Set 1 Q10

Data Structures · Stacks & Queues · Full GATE CSE 2016 Set 1 paper

GATE 2016 Set 1, Q10 1 mark · MCQ
Report issue

Stacks & Queues

Question 10, GATE 2016: An efficiently implemented array-based queue contains n items. Which complexity statement is correct? A: Both ENQUEUE and DEQUEUE can be O(1). B: At most one is O(1), with the other worst-case Ω(n). C: Both are worst-case Ω(n). D: Both are worst-case Ω(log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

A fixed-capacity circular array stores front/rear indices and wraps them modulo capacity. Enqueue writes at rear and advances it; dequeue reads at front and advances it. Both take O(1) without shifting elements, A, with overflow handled separately from dynamic resizing.

Maintain an item count or an extra full/empty flag to distinguish a full circular queue from an empty one when indices coincide. Each operation performs a bounded number of array accesses and index updates independent of n. Removing the head does not require compacting the stored elements because the front index identifies the new head. An implementation that shifts every item is possible, but the question asks what an efficient representation can achieve, not what every array implementation does.

Original paper, page 5 · Answer key