Question: How do I do part a and b for this amoritization problem? 1. Amoritization In this question, we explore a well-known trick that uses two
How do I do part a and b for this amoritization problem?

1. Amoritization In this question, we explore a well-known trick that uses two Stacks S1 and S2 to simulate the operations of a Queue Q. Consider the following implementations of ENQuEue and DeQueue. EnQueuE Q,x): if Size(S1) > 12 and IsEmPTY(S2): while not IsEmPtY(S1): PUSH(S2, PoP(S1) PUsH(S1,x) DEQUEuE Q): if IsEMPTY(S2) if IsEMPTY(S1): error "Dequeuing from an empty queue!" else: while not IsEMPTY(Si): PUSH(S2, PoP(S1) return PoP(S2) For your analysis, assume that each PusH operation takes 2 units of time, and each Pop operation takes 3 units of time. Each IsEmPtY or Size operation takes 0 unit of time. The time taken by any other pseudo-code operation is ignored (a) Consider the sequence of operations that consists of 50 EnQueue operations followed by 50 DEQUEUE operations. Use aggregate analysis to compute the amortized cost per operation for this sequence (b) Now consider any sequence of m ENQUEuE and DEQuEUE operations. Use the accounting method to derive an upper-bound on the amortized cost per operation. 1. Amoritization In this question, we explore a well-known trick that uses two Stacks S1 and S2 to simulate the operations of a Queue Q. Consider the following implementations of ENQuEue and DeQueue. EnQueuE Q,x): if Size(S1) > 12 and IsEmPTY(S2): while not IsEmPtY(S1): PUSH(S2, PoP(S1) PUsH(S1,x) DEQUEuE Q): if IsEMPTY(S2) if IsEMPTY(S1): error "Dequeuing from an empty queue!" else: while not IsEMPTY(Si): PUSH(S2, PoP(S1) return PoP(S2) For your analysis, assume that each PusH operation takes 2 units of time, and each Pop operation takes 3 units of time. Each IsEmPtY or Size operation takes 0 unit of time. The time taken by any other pseudo-code operation is ignored (a) Consider the sequence of operations that consists of 50 EnQueue operations followed by 50 DEQUEUE operations. Use aggregate analysis to compute the amortized cost per operation for this sequence (b) Now consider any sequence of m ENQUEuE and DEQuEUE operations. Use the accounting method to derive an upper-bound on the amortized cost per operation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
