AmortizedAnalysis

Insert charge 3 credits use 1 credit to insert save 2

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: f the ith insertion. ci = i 1 i 1 Starting from empty table, the cost of a sequence of n INSERT operations is: n n i=1 i=1 ci ci lg n lg n n+ n+ < < = = j =0 j =0 2j 2j n + 2n n + 2n 3n 3n ▪ 40 Dynamic table: insert only 1 2 3 4 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 41 Dynamic table: insert only Accounting. ・INSERT: charge 3 credits (use 1 credit to insert; save 2 with new item). Theorem. [via accounting method] Starting from an empty dynamic table, any sequence of n INSERT operations takes O(n) time. Pf. The algorithm maintains the invariant that there are 2 credits with each item in right half of table. ・When table doubles, one-half of the items in the table have 2 credits. ・This pays for the work needed to double the table. ▪ 42 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 1 2 3 capa...
View Full Document

Ask a homework question - tutors are online