AmortizedAnalysis

Thus there are n pop operations including those made

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: d k objects. Theorem. Starting from an empty stack, any intermixed sequence of n PUSH, POP, and MULTIPOP operations takes O(n) time. Pf. ・An object is popped at most once for each time it is pushed onto stack. ・There are ≤ n PUSH operations. ・Thus, there are ≤ n POP operations (including those made within MULTIPOP). ▪ 32 Multipop stack: accounting method Credits. One credit pays for a push or pop. Accounting. ・PUSH(S, x): charge two credits. - use one credit to pay for pushing x now - store one credit to pay for popping x at some point in the future ・No other operation is charged a credit. Theorem. Starting from an empty stack, any intermixed sequence of n PUSH, POP, and MULTIPOP operations takes O(n) time. Pf. The algorithm maintains the invariant that every object remaining on the stack has 1 credit ⇒ number of credits in data structure ≥ 0. ▪ 33 Multipop stack: potential method Potential function. Let Φ(D) = number of objects currently on the stack. ・Φ(D0) = 0. ・Φ(Di) ...
View Full Document

This document was uploaded on 02/05/2014.

Ask a homework question - tutors are online