GATE / CS ARCHIVE

GATE CSE 2017 SET 2 / QUESTION 13

GATE CSE 2017 Set 2 Q13

Data Structures · Stacks & Queues · Full GATE CSE 2017 Set 2 paper

GATE 2017 Set 2, Q13 1 mark · MCQ
Report issue

Stacks & Queues

Question 13, GATE 2017: A circular queue uses singly linked nodes, each with one next pointer, and exactly two external pointers FRONT and REAR. For O(1) insertion and deletion, which general structural conditions hold? I:front.next points to rear. II:rear.next points to front. A:I only. B:II only. C:both. D:neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. For queue order to follow next links, the circular chain must run FRONT → second → ... → REAR → FRONT. Its closing link is therefore REAR.next=FRONT, statement II.

2. To enqueue node u, set u.next=FRONT, REAR.next=u and REAR=u. To dequeue, save the old front, advance FRONT=FRONT.next and set REAR.next=FRONT. Both require only a fixed number of pointer changes, with empty and singleton cases handled separately.

3. If links instead run backward through queue order, removing the front would require finding its predecessor by traversal. Statement I is not the general rule, even though both statements happen to hold in a two-node circle. Choose B.

Original paper, page 5 · Answer key