Unformatted text preview: ‰¥ 0 for each Di.
Theorem. Starting from an empty stack, any intermixed sequence of n
PUSH, POP, and MULTIPOP operations takes O(n) time.
Pf. [Case 1: push] ãƒ»Suppose that the ith operation is a PUSH.
ãƒ»The actual cost ci = 1.
ãƒ»The amortized cost Ä‰i = ci + Î¦(Di) â€“ Î¦(Diâ€“1) = 1 + 1 = 2. 34 Multipop stack: potential method
Potential function. Let Î¦(D) = number of objects currently on the stack. ãƒ»Î¦(D0) = 0.
ãƒ»Î¦(Di) â‰¥ 0 for each Di.
Theorem. Starting from an empty stack, any intermixed sequence of n
PUSH, POP, and MULTIPOP operations takes O(n) time.
Pf. [Case 2: pop] ãƒ»Suppose that the ith operation is a POP.
ãƒ»The actual cost ci = 1.
ãƒ»The amortized cost Ä‰i = ci + Î¦(Di) â€“ Î¦(Diâ€“1) = 1 â€“ 1 = 0. 35 Multipop stack: potential method
Potential function. Let Î¦(D) = number of objects currently on the stack. ãƒ»Î¦(D0) = 0.
ãƒ»Î¦(Di) â‰¥ 0 for each Di.
Theorem. Starting from an empty stack, any intermixed sequence of n
PUSH, POP, and MULTIPOP operations takes O(n) time.
Pf. [Case 3: multipop]...
View
Full
Document
This document was uploaded on 02/05/2014.
 Spring '14

Click to edit the document details