Question: Exercise 5 . Amortized analysis. [ 1 4 points ] An ordered stack ( mathcal { S } ) is a stack
Exercise Amortized analysis.
points
An ordered stack mathcalS is a stack where the elements appear in increasing order. It supports the following operations:
operatornamepopmathcalS : Delete and return the top element from the ordered stack.
operatornamepushmathcalS x : Insert x at top of the ordered stack and reestablish the increasing order by repeatedly removing the element immediately below x until x is the largest element on the stack.
destroy mathcalS : Delete all elements in the ordered stack ie which results in an empty ordered stack
Example. The following shows an example of an ordered stack and the same stack after performing a operatornamePUSHmathcalS operation the order is reestablished by removing and The head of the stack is highlighted in gray.
beginarrayllllll
hline & & & & &
hline
endarrayRightarrow beginarrayllll
hline & & &
hline
endarray
a points What is the worstcase running time of each of the operations pop, PUSh, and destroy? No justification required.
b points We would like to apply the accounting method to make an amortized analysis of a sequence of n possibly mixed operations POP, PUSh, and destroy. Propose an amortized cost for each of these operations that guarantee the credit
Page
will never go negative while minimizing the cost. Justify your answer if the proposed amortized cost is different than
c points Now, consider any sequence of n possibly mixed operations POP, PUSH, and pestroy. At the beginning the ordered stack is empty. Using the amortized costs you proposed above, demonstrate that the credit ie the amortized cost minus the actual cost never goes negative.
d points Explain why the guarantee that the credit does not go negative helps you to conclude that the amortized cost of a single operations is O
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
