Question: Amortized cost analysis: If we use two queues data queue and working queue to implement a stack s by the following way. Suppose that both
"Amortized cost analysis:
If we use two queues data queue and working queue to implement a stack s by the
following way. Suppose that both queues have no size limit
spushitem
enQueue the item into the data queue.
spop
move all the items except the last one from the data queue to the working queue
deQueue from the data queue and return
now the names of the data queue and the working queue are swapped. That is working queue data queue and data queue working queue
a Suppose that we would like to analyze the amortized costs using the accounting method. Assume there are k items in the stack before the ith op XB eration. If the ith operation is a pop operation and we assign k amortized cost to it then how much amortized cost for a push operation should be assigned? Justify your answer.
b If the potential method is used, please define a potential function so that the amortized costs for push and pop are constant time and linear time respectively. Assume that there are k items in the stack before the ith operation. Justify your answer."
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
