AmortizedAnalysis

34 multipop stack potential method potential function

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: 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.

Ask a homework question - tutors are online