3.3.7 · D1Hashing

Foundations — Amortized O(1) operations

1,924 words9 min readBack to topic

Before you can read the parent note 3.3.7 Amortized O(1), you need to earn every symbol it throws at you. Below, each idea is built from nothing, shown as a picture, and justified by the question it answers. Read top to bottom — each block uses only what came before it.


1. What is a "cost"? (the number we count)

Why the topic needs it. Everything later ("", "amortized 3") is just adding up these steps. If you can't count steps, none of the sums make sense.

Figure — Amortized O(1) operations

2. The array and its two numbers: size and capacity

Why the topic needs it. A resize is triggered exactly when size would exceed capacity. Every formula in the parent — the potential , the load factor — is built from these two numbers.

Figure — Amortized O(1) operations

3. What "push" means, and what "resize" means

Why the topic needs it. The entire question of the topic is: resizes are slow — how slow are they on average? You must know a resize copies all current items before you can count that cost.


4. Powers of two:

Why the topic needs it. The parent writes "resizes happen at sizes ." Without powers of two, that list has no name and no formula.


5. The symbol: adding up a list

Why the topic needs it. The total copy cost of all resizes is written as one . You can't read the derivation without decoding this symbol.


6. The geometric series: why doubling stays cheap

Why the topic needs it — and why THIS tool. We use a geometric series (each term multiplied by a fixed factor 2) instead of an arithmetic series (each term plus a fixed amount) because geometric sums stay linear () while arithmetic sums blow up to quadratic (). This single choice is the difference between and amortized. See Geometric Series.

Figure — Amortized O(1) operations

7. The letter , and Big-O: naming "how it grows"

Why the topic needs it. The punchline "amortized " and the warning "additive growth is " are both statements about these shapes. See Big-O Notation.


8. Load factor : the "how full" dial (for hash tables)

Why the topic needs it. Example 2 in the parent triggers resizing off instead of "box is full," but the cost math is identical.


9. Amortized cost and : the "spread it out" idea

Why the topic needs it. The parent's formal proof uses . Without knowing is "saved work" and is "its change," those lines are unreadable.

Figure — Amortized O(1) operations

Prerequisite map

Cost = count of steps

size and capacity

push and resize

Powers of two 2 to the k

Summation sigma

Geometric series stays linear

Big-O shape of growth

Amortized cost = total over n

Load factor alpha

Potential Phi savings jar

Amortized O(1) topic


Equipment checklist

Test yourself — cover the right side.

I can say what a "cost" of 1 step physically means
One write of a number into a slot, or one copy of a number to a new box; we count steps, not seconds.
I can define size vs capacity
capacity = total slots the box has; size = slots currently filled; full means size = capacity.
I know what a push costs normally and during a resize
Normal push = 1 step; resize = copy all current items + 1 write.
I can read and list the first few powers of two
; the exponent counts how many times we doubled.
I can expand into a plain sum
— add for every counter value from 0 to m.
I know the geometric-series shortcut
, which is less than twice the last term.
I can tell , , apart by shape
Flat line, straight slope, upward-bending curve — respectively.
I can compute load factor from size and capacity
, the fraction of slots filled.
I know what amortized cost is
Total cost of n operations divided by n — the fair share each op owes.
I know what and represent
= a savings account of pre-paid work; = its change (after − before).

Connections

  • Amortized O(1) operations — the parent topic these foundations unlock.
  • Dynamic Arrays — where size/capacity/resize live.
  • Hash Tables — same resize math via rehashing.
  • Load Factor — the dial that triggers rehash.
  • Geometric Series — the fact.
  • Big-O Notation — the growth shapes.
  • Potential Method — the savings-jar formalism.
  • Stack with Multipop — another amortized example using the same jar idea.