Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q10 — Arrays, Stacks and Queues

Explain with AI

A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (nn refers to the number of items in the queue) ?

Choose one option
View worked solution

Answer: A

To implement a queue efficiently using an array, we use a circular array representation. This avoids the need to shift elements during insertion or deletion.

We maintain two pointers (or indices):

  • front: Points to the element at the front of the queue.
  • rear: Points to the element at the end of the queue.

Operations:

  1. ENQUEUE: To insert an element, we advance the rear pointer circularly and place the element at that index:rear=(rear+1)(modcapacity)\text{rear} = (\text{rear} + 1) \pmod{\text{capacity}}This operation requires only a constant number of basic steps, taking O(1)\mathcal{O}(1) time.
  2. DEQUEUE: To remove an element, we retrieve the element at the front and advance the front pointer circularly:front=(front+1)(modcapacity)\text{front} = (\text{front} + 1) \pmod{\text{capacity}}This operation also requires only a constant number of basic steps, taking O(1)\mathcal{O}(1) time.

Since both operations can be performed in constant time, Option A is the correct statement.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions