Question: Describe how to implement a queue using two stacks, so that the amortized running time for dequeue and enqueue is O(1), assuming that the stacks
Describe how to implement a queue using two stacks, so that the amortized running time for dequeue and enqueue is O(1), assuming that the stacks support constant-time push, pop, and size methods. What is the worst-case running time of the enqueue() and dequeue() methods in this case?
Step by Step Solution
3.44 Rating (151 Votes )
There are 3 Steps involved in it
Name the two stacks as E and D for we will enqueue into E and dequeue from D ... View full answer
Get step-by-step solutions from verified subject matter experts
