← Quiz: Queues and Deques: all 13 questions
Quiz: Queues and Deques · Question 12 of 13
In a queue built from two stacks, when are items moved from the in-stack to the out-stack?
In a queue built from two stacks, when are items moved from the in-stack to the out-stack?
- A.After every push
- B.After every pop
- C.Never
- D.Only when the out-stack is empty and a pop is requested
Answer & explanation
Correct answer: Only when the out-stack is empty and a pop is requested
Moving only then means each item is moved at most once, which makes each operation amortised O(1).
Can you get the rest right without peeking?
Take the timed Quiz: Queues and Deques quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →