Lecture 011

Pros&Cons Array vs. Linked list

Pros&Cons Array vs. Linked list

Amortized Analysis

k increment when flipping bits: each time cost may vary. But overall k bits time only cost O(2), not O(kn).

Mythology

  1. find out candidate amortized cost (pretend operation cost)

  2. Method

    Method

  3. Specify Token Invariant (how many tokens need to be saved)
  4. Prove operation preservation (induction)

  5. saved_before = amortized_cost - actual_cost = saved_after

Implementation ArrayList (using Array)

struct uba_header {
 int size;
 int limit;
 string[] data;
}

Doubling Size

Doubling Size

Tokens

Tokens

Cost Analysis

Cost Analysis

Table of Content