Intuition The one core idea
A hash table is just a row of numbered boxes , and a hash function is a rule that turns a key into a box number . When two keys are sent to the same box, open addressing solves the fight with a second rule — a probe sequence — that says "if this box is taken, here is the next box to try, and the next, until you find an empty one."
Everything on the parent page is built from four humble ingredients: a key , a table of slots , the mod operation , and the idea of a sequence of tries . This page earns each of them from scratch.
Before any symbol, look at the object we are storing things in.
Definition Slot, index, table
A table is a fixed-length row of boxes. Each box is a slot . Each slot has an address called its index — a whole number counting from 0 .
The picture shows 7 slots with indices 0 , 1 , 2 , 3 , 4 , 5 , 6 .
"Index 0 " is the first box, not the second. Computers count from zero.
We will call the number of slots m . In the picture m = 7 .
Intuition Why count from zero?
Because the wrap-around trick (next section) uses remainders, and remainders naturally live in the range 0 , 1 , … , m − 1 . Starting at 0 makes "index" and "remainder" the same set of numbers — no awkward off-by-one.
A key k is the piece of data we want to store or look up — here always a whole number (like 85 or 700 ).
Picture: a luggage tag with a number written on it. We must decide which slot this tag belongs in.
The whole game is a function from keys (possibly huge numbers) to slots (only m of them). Many keys, few slots — collisions are inevitable. Hold that thought.
Everything uses mod . If you are shaky here, nothing else lands. So we build it slowly.
a mod m (the remainder)
a mod m is the remainder left over when you divide a by m and throw away the whole-number part.
50 mod 7 : how many 7 s fit in 50 ? Seven 7 s make 49 , leaving 1 . So 50 mod 7 = 1 .
700 mod 7 : exactly one hundred 7 s make 700 , leaving 0 . So 700 mod 7 = 0 .
The picture that makes mod obvious is a clock .
mod = a circular ruler
Lay the numbers 0 , 1 , 2 , … around a circle with m marks. Counting past the top wraps back to 0 . A clock is exactly mod 12 : three hours after 11 o'clock is 2 , because ( 11 + 3 ) mod 12 = 2 .
This is why hash tables use mod: no matter how large the key, mod m folds it back into the range 0 … m − 1 — always a valid slot index . It is the tool that squeezes infinitely many keys into finitely many boxes.
mod gives the quotient."
No. mod gives the remainder . 50 mod 7 = 1 (remainder), while 50 ÷ 7 = 7 (quotient, discarded). Only the remainder tells us the slot.
Now we name the rule that turns a key into its home slot.
Definition Base hash function
h 1 ( k )
h 1 ( k ) is the rule "where does key k live if nobody is in the way? " On the parent page it is the division method :
h 1 ( k ) = k mod m .
h 1 ( 85 ) = 85 mod 7 = 1 → 85 's home slot is 1 .
Picture: an arrow from the luggage tag 85 pointing straight at box 1 .
The little subscript 1 just means "hash number one " — we keep the name free because double hashing will introduce a second hash, h 2 , later. (Why the division method and other choices exist is a separate story: see Hash functions — division & multiplication methods .)
Intuition Why do we even need a hash function?
Without one, finding a key means scanning the whole table (m steps). A hash function jumps directly to the likely slot in one step. That is the entire speed advantage of hashing.
Collisions are the entire reason open addressing exists. The parent contrasts two cures:
Hashing — chaining — hang colliding keys in a list outside the table.
Open addressing — keep everyone inside the table, using a probe rule (next section).
i
i is the try counter : i = 0 is your first attempt (the home slot), i = 1 the second attempt, and so on.
Picture: footprints numbered 0 , 1 , 2 , … as you walk the table hunting for an empty box.
Definition Offset function
f ( i )
f ( i ) is how far from home to jump on try i . It must satisfy f ( 0 ) = 0 so that try zero is always the home slot .
Linear: f ( i ) = i → jumps 0 , 1 , 2 , 3 , … (crawl one at a time).
Quadratic: f ( i ) = i 2 → jumps 0 , 1 , 4 , 9 , … (leap further each time).
Double: f ( i ) = i h 2 ( k ) → jumps in steps of a key-specific size.
Worked example Reading the template out loud (linear,
m = 7 )
Insert 85 with h 1 ( 85 ) = 1 , and slot 1 is already full.
i = 0 : ( 1 + 0 ) mod 7 = 1 → full, keep going.
i = 1 : ( 1 + 1 ) mod 7 = 2 → empty! Place 85 in slot 2 .
This is exactly the parent's worked example — now every symbol in it is defined.
Definition Probe sequence
The probe sequence is the ordered list of slots the template visits as i = 0 , 1 , 2 , … :
h ( k , 0 ) , h ( k , 1 ) , h ( k , 2 ) , …
Picture: the numbered footprints from figure s04, in order.
This is precisely why the parent worries about h 2 ( k ) being coprime to m and about m being prime — those conditions are what force the sequence to be a full permutation. (Coprime = "share no common factor except 1 "; more on prime sizes in Prime table sizes .)
α is the single most important number
Every probability on the parent page ("chance a slot is occupied ≈ α ") and every cost formula (1/ ( 1 − α ) ) is a function of α alone . As α → 1 the cost blows up, which is why we rehash into a bigger table before it fills — see Load factor and rehashing .
The parent derives expected probes with a ∑ . If that squiggle is unfamiliar, here it is from zero.
i = 0 ∑ ∞ t i
The big Greek S ("sigma") means "add up a list of terms." The i = 0 underneath is the starting counter; the ∞ on top means "keep going forever."
∑ i = 0 ∞ α i = α 0 + α 1 + α 2 + ⋯ = 1 + α + α 2 + ⋯
Picture: stacking bars of heights 1 , α , α 2 , … that shrink toward zero (because α < 1 ), so the stack has a finite total .
Probe index i and offset f
Read it as: the table , mod , and key combine into the base hash ; a base hash makes collisions possible; collisions demand a probe rule ; the probe rule must form a permutation ; and separately, α plus the ∑ give the cost formulas. All roads feed the topic.
Cover the right side. If you can answer every one, you are ready for the parent topic .
What does index 0 refer to in a table of m slots? The very first slot; computers count from zero, so valid indices are 0 through m − 1 .
Compute 85 mod 7 . 1 (since 7 × 12 = 84 , remainder 1 ).
Why does a hash function use mod m? mod m folds any key into the range 0 … m − 1 , which is always a legal slot index.
What is a collision? Two different keys map to the same home slot: h 1 ( k 1 ) = h 1 ( k 2 ) .
What must f ( 0 ) equal, and why? f ( 0 ) = 0 , so the first probe (i = 0 ) always lands on the home slot h 1 ( k ) .
Write the general probe template. h ( k , i ) = ( h 1 ( k ) + f ( i )) mod m .
What does "permutation of all m slots" guarantee? Every slot is eventually visited, so an insert never fails while an empty slot still exists.
Define the load factor α . α = n / m , the fraction of slots that are filled; 0 ≤ α < 1 .
What does ∑ i = 0 ∞ α i equal for 0 ≤ α < 1 ? 1 − α 1 (the geometric series sum).
Why start counting slots at 0 instead of 1 ? So slot indices and mod m remainders are the exact same set of numbers 0 … m − 1 .