Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q13 — Arrays, Stacks and Queues

Explain with AI

A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the following statements is/are CORRECT for such a circular queue, so that insertion and deletion operations can be performed in O(1)O(1) time?

  1. Next pointer of front node points to the rear node.
  2. Next pointer of rear node points to the front node.
Choose one option
View worked solution

Answer: B

In a circular queue implemented using a singly linked list, the elements are ordered from FRONT to REAR. To maintain circularity, the last node (REAR) must point back to the first node (FRONT). Thus, Statement II is correct.

Let's analyze the operations under this configuration:

  • Deletion (Dequeue): To delete from the front, we update FRONT to point to the next node (i.e., FRONT = FRONT->next) and update the REAR->next pointer to the new FRONT. This takes O(1)\mathcal{O}(1) time. If Statement I were true (i.e., FRONT->next pointed to REAR), we would lose the link to the second node in the queue, making deletion of the front node impossible in O(1)\mathcal{O}(1) time for queues of size greater than 2.
  • Insertion (Enqueue): To insert a new node N at the rear, we set N->next = REAR->next (which is FRONT), then update REAR->next = N, and finally set REAR = N. This also takes O(1)\mathcal{O}(1) time.

Hence, only Statement II is correct, making B the correct option.

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

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