3.3.7 · D3Hashing

Worked examples — Amortized O(1) operations

3,336 words15 min readBack to topic

Before we start, three words that will appear on every line — earned now, in plain English:


The scenario matrix

Every cell below is a distinct situation the doubling machine can be in. The examples that follow are tagged with the cell(s) they cover, so together they fill the whole grid.

Cell Situation Covered by
A Smallest non-trivial run — trace every push, tiny Ex 1
B Degenerate: empty array () and single push () Ex 2
C Exact power of two () — resize on the very last push Ex 3
D Just past a power of two () — the worst-case latency spike Ex 3
E Different growth factor (grow ) — is it still ? Ex 4
F Failing factor: additive growth — quadratic blow-up Ex 5
G Hash-table rehash driven by load factor Ex 6
H Shrinking / degenerate: pop-heavy sequence, avoid "thrashing" Ex 7
I Word problem — real-world sizing decision Ex 8
J Exam twist — mixed push/pop, potential-method proof Ex 9

Prerequisites in play: Dynamic Arrays, Hash Tables, Load Factor, Geometric Series, Big-O Notation, Potential Method, Stack with Multipop.


Cell A — trace the smallest run

Figure — Amortized O(1) operations

Cell B — the degenerate ends


Cells C & D — on and just past a power of two


Cell E — a different growth factor

Figure — Amortized O(1) operations

Cell F — the factor that fails


Cell G — hash-table rehash


Cell H — shrinking without thrashing


Cell I — real-world sizing


Cell J — exam twist (potential method, mixed push/pop)


Recap

Recall Which cells failed the

test, and why? Only Cell F (additive growth) fails ::: arithmetic series → total → amortized; every multiplicative-factor case (Cells A–E, G, I) and the two-sided stack (H, done right) stay .

Recall What single number changes when you change the growth factor?

The amortized constant (e.g. for , for ) ::: the big-O class stays ; only the constant moves.


Connections

  • Amortized O(1) operations — parent; this page is its full case-matrix.
  • Geometric Series — the bound used in Cells D, E, I.
  • Dynamic Arrays — Cells A–F.
  • Hash Tables · Load Factor — Cell G rehash.
  • Stack with Multipop — Cell H shrinking.
  • Potential Method — Cell J proof.
  • Big-O Notation — the class every cell is measured against.