3.3.1 · D1Hashing

Foundations — Hash function — properties - deterministic, uniform, fast

2,020 words9 min readBack to topic

This page assumes you have seen nothing. Before you read the parent note, you need every symbol it throws at you. We build them one at a time, each on top of the last.


0. The mailbox picture that everything hangs on

Picture a wall of numbered mailboxes. You get a letter with a name on it. You need a rule that reads the name and points at exactly one box. That rule is the hash function. Hold this picture — every symbol below is a label on some part of it.


1. What is a "key"?

Picture: the name written on the front of the letter.

Why the topic needs it: hashing is about finding things by their key without searching everything. No key, nothing to look up.


2. The set-builder braces and "element of"

The parent writes and . These are just two pieces of shorthand.

Picture: is the list of box numbers written under each mailbox. points at one of them.


3. Table size and the universe

Picture: is the handful of boxes on the wall. is the whole city of every possible name that could ever be mailed.

Why the topic needs it: because there are more keys than boxes, two keys must eventually share a box. That forced sharing has a name — the Pigeonhole Principle — and the whole idea of collision resolution exists only because of it.


4. What a function actually says

This one line is the heart of the parent note. Let's earn every piece.

Picture: an arrow leaving a name in the city and landing on exactly one box on the wall.

Why the topic needs it: every property in the parent — deterministic, uniform, fast — is a sentence about . You cannot read those sentences until means something concrete.


5. The equals / implies chain:

So reads: "if two keys are the actual same key, the rule must give them the same box." That is determinism — the plainest possible demand: don't change your mind.

Picture: feed the same name in twice → the arrow lands on the same box both times.


6. Probability and the fraction

The parent writes . Two ideas hide here.

Picture: a pie sliced into identical wedges. See Modular Arithmetic for how real rules chop keys into those wedges.


7. Counting keys: , and the load factor

Picture: letters shared over boxes → each box holds about letters. That "2" is .


8. The summation sign and "expected value"

The parent derives chain length with and . Both are just "add things up".

Picture: coin-flips, each with a small chance of "lands here"; the pile you expect to see is their total chance.


9. The mod operator

Every real hash rule ends in this.

Picture: a number line wrapped around a circle of marks; wherever lands on the circle is its box.


10. Base- / powers (for string hashing)

Picture: the same three letters shuffled — plain sum keeps one flat pile; weighted sum stacks them at different heights, so shuffles look different.


The prerequisite map

Key - the input name

Function h maps key to box

Sets and element-of

Universe U vs table size m

Pigeonhole - collisions forced

Deterministic - same key same box

Probability and one-over-m

Uniform - fair spread

Summation and expected value

Load factor alpha

Modular arithmetic - mod m

Fast rule via mod

Position weights p to the i

Hash function properties DUF


Equipment checklist

Cover the right side and answer aloud. If any stalls, reread that section.

The symbol means
"is one of / is a member of".
lists which things
the box numbers, from 0 up to (there are of them).
In , what is
the universe — every key that could ever possibly appear.
Why is important
far more possible keys than boxes, so collisions are forced (pigeonhole).
evaluates to
the box number the rule assigns to key .
states which property
deterministic — same key always lands in the same box.
means
every box is equally likely — a perfectly uniform (fair) rule.
The load factor measures
average fullness — expected number of keys per box.
equals
(add to itself times).
equals
(remainder after dividing 50 by 7).
Why use weights in a string hash
so letter order matters — "abc" and "cab" get different hashes.

Connections