Question: please answer the full question and write neatly Problem 1 (20 points). Consider a FIFO queue implemented by two stacks, S, and S2. It implements
Problem 1 (20 points). Consider a FIFO queue implemented by two stacks, S, and S2. It implements the FIFO queue operations as follows: ENQUEUE(I): S.PUSH(r) DEQUEUE(): If S, is not empty, return S2. Por(). If Sy is empty, Por all the elements of S, PUSI them onto S2, then return S2. POP(). (a) Show the contents of stacks S, and S, after this sequence of operations: ENQUEUE(1), ENQUEUE(2), DEQUEVE). ENQUEUE(3), DEQUEUE, ENQUEUE(4) (b) For a sequence of n operations, use aggregate analysis to show that the amortized cost for each operation is (1) (c) For a sequence of n operations, tise the potential method to show that the amortized cost for each operation is 0(1). Show that (D) = 2 . S size is a valid potential function and use it to compute the amortized cost
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
