Amortised Analysis · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Cheap usually, rare splurge, fair average

Computing · Algorithms & Data Structures · ages 19-21
Name ______________________   Date ____________
  1. When does a doubling array pay a big copy?

    • On every append
    • When items are read
    • Only when the array fills
  2. What does an amortised bound describe?

    • One lucky input
    • The average over any sequence
    • The cost of one line of code
  3. An amortised bound is an average-case claim about random inputs.

    Circle one:   True   False

  4. A resize copies 8 items. What pays for it?

    • The stored credits on those slots
    • A faster processor
    • Deleting other arrays
  5. Each cheap append stores 2 credits. After 4 such appends, type the stored credits.

    Answer: ______________

  6. Why does a million appends cost a few million steps, not a million squared?

    • Copies thin out as the array grows
    • Appends skip writing entirely
    • Squares round down at scale
  7. With three coins per append, a hostile sequence can still break the constant average.

    Circle one:   True   False

  8. A critic points at one copying append and calls the structure linear per append. What is the flaw?

    • Copying appends never occur
    • One costly call cannot price a whole run
    • Arrays forbid all analysis
LightMySky · lightmysky.comW1-mt_1zLrl5RKGr-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Cheap usually, rare splurge, fair average W1-mt_1zLrl5RKGr-s1

  1. Only when the array fills · Full arrays copy into a doubled home.
  2. The average over any sequence · It averages a run, whatever the sequence.
  3. False · It is a worst-case promise over any sequence.
  4. The stored credits on those slots · Prepaid credits cover the copy run.
  5. 8 · Four appends times two credits makes eight.
  6. Copies thin out as the array grows · Doubling spaces the costly copies wider apart.
  7. False · The promise holds for any sequence.
  8. One costly call cannot price a whole run · Amortised pricing spreads rare costs across the run.
Worksheet · LightMySky