Question: In this problem we have two stacks A and B ( recall that a stack allows us to push elements onto it and to pop
In this problem we have two stacks A and B recall that a stack allows us to push elements onto it and to pop elements off of it in LIFO order In what follows, we will use n to denoate the number of elements in stack A and use m to denote the number of elements in stack B Suppose that we use these stacks to implement the following operations:
beginitemize
item PushAx: Push element x onto A
item PushBx: Push element x onto B
item BigPopAk: Pop min n k elements from A
item BigPopBk: Pop min m k elements from B
item Movek: Repeatedly pop one element from A and push it into B until either k elements have been moved or A is empty.
enditemize
We are using the stacks A and B as black boxes you may assume that PushA, PushB, BigPopA and BigPopB each take one unit of time ie it takes one time to step to push or pop a single element
Prove that the amortized running time of each operation is O You may use either a potential function $Phi$ n m or a banking scheme, but must use one or the other.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
