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 time?
- Next pointer of front node points to the rear node.
- Next pointer of rear node points to the front node.
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
FRONTto point to the next node (i.e.,FRONT = FRONT->next) and update theREAR->nextpointer to the newFRONT. This takes time. If Statement I were true (i.e.,FRONT->nextpointed toREAR), we would lose the link to the second node in the queue, making deletion of the front node impossible in time for queues of size greater than 2. - Insertion (Enqueue): To insert a new node
Nat the rear, we setN->next = REAR->next(which isFRONT), then updateREAR->next = N, and finally setREAR = N. This also takes time.
Hence, only Statement II is correct, making B the correct option.
Free practice · Your answers on this page are not saved.
