GATE | GATE-CS-2017 (Set 2) | Question 30

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

I. Next pointer of front node points to the rear node.
II. Next pointer of rear node points to the front node.

(A) I only

(B) II only
(C) Both I and II
(D) Neither I nor II

Answer: (B)

Explanation: Since, Circular queue deletes an item using Front pointer and insert an element using Rear pointer. If we want to insert an element into circular queue then we have to increment Rear pointer to next node then insert element. Then after update the next pointer of Rear node to the Front node. This method will have O(1) time for Insertion and Deletion.
Only statement (ii) is true. So, option (B).

Quiz of this Question

My Personal Notes arrow_drop_up