AmortizedAnalysis

too many items inserted expand table too many items

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: ・Suppose that the ith operation is a MULTIPOP of k objects. ・The actual cost ci = k. ・The amortized cost ĉi = ci + Φ(Di) – Φ(Di–1) = k – k = 0. ▪ 36 A MORTIZED A NALYSIS ‣ binary counter ‣ multipop stack ‣ dynamic table SECTION 17.4 Dynamic table Goal. Store items in a table (e.g., for hash table, binary heap). ・Two operations: INSERT and DELETE. - too many items inserted ⇒ expand table. - too many items deleted ⇒ contract table. ・Requirement: if table contains m items, then space = Θ(m). Theorem. Starting from an empty dynamic table, any intermixed sequence of n INSERT and DELETE operations takes O(n2) time. Pf. A single INSERT or DELETE takes O(n) time. ▪ overly pessimistic upper bound 38 Dynamic table: insert only ・Initialize table to be size 1. ・INSERT: if table is full, first copy all items to a table of twice the size. insert old size new size cost 1 1 1 – 2 1 2 1 3 2 4 2 4 4 4 – 5 4 8 4 6 8 8 – 7 8 8 – 8 8 8 – 9 8 16 8 ⋮ ⋮ ⋮ ⋮ Cost model. Number of items that are copied. 39 Dynamic table: insert only Theorem. [via aggregate method] Starting from an empty dynamic table, any sequence of n INSERT operations takes O(n) time. Pf. Let ci denote the cost o...
View Full Document

Ask a homework question - tutors are online