Problem 4 amortized analysis suppose we have a stack

Info icon This preview shows pages 5–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Problem 4: Amortized Analysis Suppose we have a stack implemented as a linked list. We have Push oper- ation as usual. However this stack does not have a Pop operation. Instead, it has Pop-half operation which removes d S/ 2 e elements from the top of the stack, where S is the number of elements in the stack. In order to perform Pop-half efficiently, we have to keep track of the middle element in the list. Therefore every time we push an element, we pay $1 to push and an addi- tional $1 to check and update the middle element. This makes the actual cost of Push $2. We pay $1 to remove each element from the stack and $1 for releasing its memory. Thus, if there are S elements in the stack, Pop- half costs $ d S/ 2 e to remove the elements and $ d S/ 2 e to release their memory. a) What is the worst sequence of operations? What is its total cost? b) Perform an amortized analysis of the running time of n operations on this stack. State your answer in terms of the average cost per operation, in dollars. 5
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Intentionally blank 6
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern