GATE Computer ScienceHardGATE CS (PYQ pattern)
A circular queue stores items in an array of 8 slots (indices 0 to 7) and keeps two fields, front (index of the first item) and count (number of items); an item is enqueued at index (front + count) % 8, a dequeue advances front by 1 mod 8, and all 8 slots can be used. An enqueue on a full queue or a dequeue on an empty one fails and changes nothing. Starting from front = 6 and count = 0, the operations E E E E E D D E E E E E E D E E D D D E are applied (E = enqueue, D = dequeue). How many operations fail, what is front at the end, and at which index was the last item stored?
- A. 2 failed, front = 4, last item at index 1
- B. 3 failed, front = 4, last item at index 0
- C. 2 failed, front = 4, last item at index 2
- D. 3 failed, front = 3, last item at index 1
Correct answer: A. 2 failed, front = 4, last item at index 1
Track (front, count): 5 enqueues give count 5; 2 dequeues move front to 0 with count 3; the next 6 enqueues fill the array (count 8) after 5 of them, so the 6th fails; D, E, E: front 1, count 8 again after one E and the second E fails; D D D give front 4, count 5; the final E goes to (4 + 5) % 8 = 1. In total 2 failures, front = 4, last index 1. Treating the queue as having only 7 usable slots gives 3 failed, front = 4, last item at index 0.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- The infix expression a + b (c ^ d - e) ^ (f + g h) - i (with ^ right-associative and higher than and +) is converted to postfix with the…
- Evaluate the postfix expression 9 3 - 4 2 5 - 7 3 / + where / is integer division truncating toward zero.
- Ten people numbered 1 to 10 stand in a circle (a circular linked list in increasing order). Counting starts at person s, who is counted as…
- A singly linked list has 17 nodes numbered 0 to 16 from the head; node 16 points back to node 7 (so the tail of length 7 leads into a…
- A routine rev(k) reverses every block of k consecutive nodes of a singly linked list in place, leaving a final block of fewer than k nodes…
- A queue is built from two stacks: enqueue pushes onto stack IN; dequeue pops from OUT, and if OUT is empty it first moves every element of…