Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
A circular queue of capacity 5 starts empty and runs this sequence in order: enqueue(2), enqueue(3), enqueue(3), enqueue(2), enqueue(3), dequeue(), enqueue(4). What are its final contents, front to rear (dequeue on empty is a no-op)?
- A. 4, 3, 2, 3, 3
- B. 3, 3, 2, 3, 4
- C. empty
- D. 3, 3, 2, 3
Correct answer: B. 3, 3, 2, 3, 4
A circular queue wraps the rear index modulo its capacity instead of shifting elements on dequeue; tracing front/rear/size through all 7 operations in order leaves [3, 3, 2, 3, 4] 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
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- Keys 26, 63, 80, 39, 14, 99, 18, 93, 44 are inserted via linear probing (h(k) = k mod 11, probe by +1 on collision) into an initially…
- A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(3), enqueue(1), enqueue(6), enqueue(9), dequeue()…
- What is the postfix (Reverse Polish) form of the infix expression "i (f + c)- a / h", built with the standard stack-based conversion (^…
- Array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is left-rotated by d = 1 positions using the reversal algorithm (reverse first d, reverse rest…
- A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(7)?