Data Structures & AlgorithmsHardGATE CS
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) mod 6 (rejected if count = 6); a dequeue advances front by 1 mod 6. The operations are E10 E20 E30 E40 E50 D D E60 E70 D E80 E90 D D E11 (E = enqueue the value, D = dequeue). After all operations, what are the index of the front element and the index of the rear (last) element?
- A. front = 5, rear = 4
- B. front = 4, rear = 2
- C. front = 5, rear = 3
- D. front = 0, rear = 3
Correct answer: C. front = 5, rear = 3
Tracking count: after the first five enqueues count = 5; two dequeues leave 3 (front = 2); E60 and E70 bring it to 5, D leaves 4 (front = 3), E80 and E90 would reach 6 (all accepted), then D D leave 4 (front = 5), and E11 gives count = 5. The front is index 5 and the rear is (5 + 5 − 1) mod 6 = 3. Final array: [70, 80, 90, 11, None, 60].
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
- 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…
- The span of a day is the number of consecutive days ending that day (including it) whose price is at most that day's price. For prices…
- Bars of unit width have heights [3, 0, 2, 0, 4, 0, 1, 3, 0, 2, 5, 1, 0, 3]. After rain, how many units of water are trapped between the…
- For the array [3, 1, 2, 4, 1, 5, 2, 6], what is the sum of the minimum element over all contiguous subarrays?
- How many non-empty contiguous subarrays of [5, 2, -3, 8, 6, -9, 4, 7, 1, 3, 12, -5, 6, 2] have a sum divisible by 7?