Data Structures & AlgorithmsVery hardGATE CS (PYQ pattern)
A circular queue uses an array of size 5 with the convention that front is the index of the next element to dequeue, rear is the index of the next enqueue, and the queue is full when (rear + 1) mod 5 = front. Starting empty: enqueue 1, 2, 3, 4, 5, dequeue, dequeue, enqueue 6, 7, 8, dequeue, enqueue 9, dequeue. Which enqueues are rejected, and what are the final front and rear?
- A. Rejected 5 and 8; front = 4, rear = 2
- B. Rejected 8 only; front = 4, rear = 3
- C. Rejected 5 and 8; front = 3, rear = 2
- D. Rejected 5 only; front = 4, rear = 3
Correct answer: A. Rejected 5 and 8; front = 4, rear = 2
This convention wastes one slot, so only 4 elements fit: 5 is rejected at once. After two dequeues 6 and 7 fit, making it full again, so 8 is rejected. Two more dequeues remove 3 and 4, leaving 6, 7 and 9 with front = 4 and rear = 2.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- The integers 1, 2, 3, 4, 5, 6 are pushed onto an initially empty stack in this order; pops may happen at any time, and the 6 popped values…
- A hash table of size 11 uses double hashing: the probe sequence for key k is (k mod 11 + i · (7 − (k mod 7))) mod 11 for i = 0, 1, 2…
- A hash table of size 7 uses h(k) = k mod 7 with linear probing. A delete leaves a tombstone, an insert goes into the first empty or…
- A circular queue is stored in an array of size 6 (indices 0-5). Initially empty, front = 0, and an enqueue stores at index (front + count)…
- A singly linked list holds 1, 2, ..., 11 in order. Starting from the head, every alternate group of k = 3 consecutive nodes is reversed in…
- For the array [7, 2, 4, 9, 3, 5, 1, 8, 6, 2, 10, 4, 3, 9] and window size k = 4, compute (maximum - minimum) for every window of k…