{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

AmortizedAnalysis

# Di di1 2 amortized costs i ci di di1 1

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: city of array 4 5 6 43 Dynamic table: insert only Theorem. [via potential method] Starting from an empty dynamic table, any sequence of n INSERT operations takes O(n) time. Pf. Let Φ(Di) = 2 size(Di) – capacity(Di). number of elements capacity of array Case 1. [does not trigger expansion] size(Di) ≤ capacity(Di–1). ・Actual cost ci = 1. ・Φ(Di) – Φ(Di–1) = 2. ・Amortized costs ĉi = ci + Φ(Di) – Φ(Di–1) = 1 + 2 = 3. Case 2. [triggers expansion] size(Di) = 1 + capacity(Di–1). ・Actual cost ci = 1 + capacity(Di–1). ・Φ(Di) – Φ(Di–1) = 2 – capacity(Di) + capacity(Di–1) = 2 – capacity(Di–1). ・Amortized costs ĉi = ci + Φ(Di) – Φ(Di–1) = 1 + 2 = 3. ▪ 44 Dynamic table: doubling and halving Thrashing. ・Initialize table to be of fixed size, say 1. ・INSERT: if table is full, expand to a table of twice the size. ・DELETE: if table is ½-full, contract to a table of half the size. Efficient solution. ・Initialize table to be of fixed size, say 1. ・INSERT: if table is full, expand...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online