Data Structures & AlgorithmsVery hardGATE CS · DSA
A circular queue of capacity 5 starts empty and runs this sequence in order: enqueue(6), dequeue(), enqueue(4), enqueue(6), dequeue(), enqueue(4), enqueue(5), enqueue(5), enqueue(8). What are its final contents, front to rear (dequeue on empty is a no-op)?
- A. 8, 5, 5, 4, 6
- B. 6, 4, 5, 5, 8
- C. 6, 4, 5, 5
- D. empty
Correct answer: B. 6, 4, 5, 5, 8
A circular queue wraps the rear index modulo its capacity instead of shifting elements on dequeue; tracing front/rear/size through all 9 operations in order leaves [6, 4, 5, 5, 8] from front to rear.
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 Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [9, 6, 6, 6, 6, 5, 6]. What candidate and final…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- What does this loop-counting code print? (Python) python n, c = 22, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)
- Kadane's algorithm runs on the array [6, 9, 2, 7, -4, -9, -5, 1, 3, 4] to find the maximum sum of a contiguous subarray. What sum does it…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "BABAAABCC" are anagrams of "AB"?