Skip to content

hashing and load

shapes of data

what it is

A hash table works out a key's slot from the key, so a look up goes straight there. The load, keys over slots, says how many keys a look up for a key not there checks, on average.

A hash table keeps keys in slots numbered from 0, here slots 0 to 6. A hash function works out a key's slot number from the key. The simplest takes the remainder after dividing by 7, the number of slots. 17 is 2 sevens and 3 over, so 17 goes in slot 3. A look up for 17 works out 3 again and looks there alone.

01921734125206slot
Keys 17, 9, 20 and 12 go in slots 3, 2, 6 and 5.

A word is no number, so make one. Number the letters from a as 1 to z as 26. Keep a running total from 0, and for each letter in turn multiply it by 26, the base, and add the letter's number. The drawing runs it on cab, the letters 3, 1, 2.

lettertotalnew totalc0× 26 +3=3a3× 26 +1=79b79× 26 +2=2,0562,056 = 293 × 7 + 5, slot5
2,056 is 293 sevens and 5 over, so cab goes in slot 5.

Two keys can want one slot. 31 leaves 3 over, like 17: a collision. Chaining keeps both in slot 3, a chain, the newest on top. With more keys than slots, no hash function avoids it: 8 keys in 7 slots must put two in one. Books call this the pigeonhole principle.

3502219217313412405206slotlanded where a key already was
31 joins 17 in slot 3, and 40 joins 12 in slot 5, though slot 4 stays empty.

The load is keys over slots, so 14 keys in 7 slots is a load of 2. A look up for a key not there compares it with every key in its slot, one look each. On average, that walk is the load.

3501221529139211731333401240263354204862slotkeyslanded where a key already was
Each slot's count under it.

Every hash function sends some keys all to one slot: the remainder by 7 sends 0, 7, 14, 21 and 28 to slot 0. Someone who knows it can choose them, and make every look up walk one long chain. So pick the function at random when the table is made, from a family. A member multiplies a key by 1 to 28 and adds 0 to 28: 28 times 29, 812 members, as times 0 would send every key to one slot. Then it takes the remainder by 29, a prime bigger than every key, here 0 to 28, and then by 7. Two keys share a slot under only 92 of the members, about 1 in 9, under 1 in 7 (question 5).

remainder by 7071421280123456slottimes 4, plus 4280211142730456slottimes 10, plus 1002112314457286slotlanded where a key already was
Times 10, plus 1 still pairs 0 with 21 and 7 with 28: a member can collide too.
keytimes 4, plus 4by 29slot
0444
73233
146022
218811
2811600
Times 10, plus 1 takes 0 and 21 to 1 and 211, which leave 1 and 8 by 29, both slot 1.

where the formulas come from

Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about nn, or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.

question 1Which slot does a whole number key kk go in, among 7, and why is it always one of 0 to 6?
  1. the move: the sevens that fit

    the line:
    ⌊k/7⌋ sevens fit in k\begin{gathered} \lfloor k/7 \rfloor \text{ sevens fit in } k \end{gathered}
    keysevens that fitleft over
    1723
    912
    2026
    1215
    3143
    What is left over is the key's slot.

    why it is allowed: ⌊k/7⌋\lfloor k/7 \rfloor is kk over 7 rounded down. 17 over 7 is about 2.4, so 2 sevens fit in 17.

  2. the move: the slot is what is left

    the line:
    S=k−7⌊k/7⌋S = k - 7\lfloor k/7 \rfloor

    why it is allowed: Let SS be the slot, kk with the sevens taken out. For 17, 17 take away 14 is 3.

  3. the move: never below 0

    the line:
    S≥0S \ge 0

    why it is allowed: The sevens that fit add up to at most kk, so taking them out leaves 0 or more.

  4. the move: never above 6

    the line:
    S≤6S \le 6

    why it is allowed: Were 7 or more left over, one more seven would fit, but line 1 already counted every seven that fits.

  5. the move: read it

    the line:
    every key gets one ofthe slots 0 to 6\begin{gathered} \text{every key gets one of} \\ \text{the slots 0 to 6} \end{gathered}

    why it is allowed: By lines 3 and 4.

try it with a small kk: at k=12k = 12, line 2 gives S=5S = 5, which you can work out by hand

question 2cab is the letters 3, 1, 2. Read them as a number in a base rr, as the digits 3, 1, 2 read 312 in base 10. Why does the running total give that number?
  1. the move: adding forgets the order

    the line:
    bad and dab, added up,are both 7\begin{gathered} \text{bad and dab, added up,} \\ \text{are both 7} \end{gathered}
    wordlettersaddedslot
    bad2, 1, 470
    dab4, 1, 270
    Added up, both go in slot 0.

    why it is allowed: Adding is simpler, but bad and dab hold the same letters, so they always share a slot. A base makes each letter's place count.

  2. the move: each place counts

    the line:
    N=3r2+1×r+2N = 3r^2 + 1 \times r + 2
    word676261
    bad214
    dab412
    26 times 26 is 676. bad is 2 times 676, plus 26, plus 4, so 1,382, slot 3. dab is 2,732, slot 2.

    why it is allowed: 312 is 3 times 100, plus 1 times 10, plus 2. Let NN be cab's number in base rr. The first letter counts rr times rr, the next letter rr, and the last 1.

  3. the move: take r out of the first two

    the line:
    N=(3r+1)r+2N = (3r + 1)r + 2

    why it is allowed: 3r23r^2 is 3r3r times rr, so the first two terms share the factor rr.

  4. the move: start from 0

    the line:
    N=((0×r+3)r+1)r+2N = ((0 \times r + 3)r + 1)r + 2
    lettertotalnew totalc0× 10 +3=3a3× 10 +1=31b31× 10 +2=312
    The running total in base 10.

    why it is allowed: 0 times rr, plus 3, is 3, so nothing changes. Now read it from the inside out.

  5. the move: read it

    the line:
    from 0: times r, plus the nextletter, for each letter in turn\begin{gathered} \text{from 0: times } r\text{, plus the next} \\ \text{letter, for each letter in turn} \end{gathered}

    why it is allowed: Line 4, inside out, is the running total. Books call it Horner's rule. It multiplies once a letter, and never works out a power.

try it with a small rr: at r=10r = 10, line 2 gives N=312N = 312, which you can work out by hand

question 3Put nn keys in 7 slots, by any hash function. How many keys must the fullest slot hold, at least?
  1. the move: the answer

    the line:
    the fullest slot holdsat least ⌈n/7⌉ keys\begin{gathered} \text{the fullest slot holds} \\ \text{at least } \lceil n/7 \rceil \text{ keys} \end{gathered}
    3502219217313114125206slotlanded where a key already was
    7 keys fill the 7 slots, one each. The 8th, 31, must join one of them, 17 in slot 3.

    why it is allowed: ⌈n/7⌉\lceil n/7 \rceil is nn over 7 rounded up: 8 over 7 is about 1.14, rounded up 2. If every slot held fewer, the slots would hold fewer than nn keys.

  2. the move: suppose fewer

    the line:
    say each slot holds atmost ⌈n/7⌉−1 keys\begin{gathered} \text{say each slot holds at} \\ \text{most } \lceil n/7 \rceil - 1 \text{ keys} \end{gathered}

    why it is allowed: Pretend line 1 fails, and watch the keys not fit. Then every slot holds fewer than ⌈n/7⌉\lceil n/7 \rceil. Counts are whole numbers, so that is at most ⌈n/7⌉−1\lceil n/7 \rceil - 1: for 8 keys, fewer than 2 means at most 1.

  3. the move: what the 7 slots hold

    the line:
    C=7(⌈n/7⌉−1)C = 7(\lceil n/7 \rceil - 1)

    why it is allowed: Let CC be the most such slots hold together. For 8 keys, 1 a slot, 7 in all.

  4. the move: rounding up adds under 1

    the line:
    ⌈n/7⌉≤n7+67\lceil n/7 \rceil \le \frac{n}{7} + \frac{6}{7}
    keys⌈n/7⌉\lceil n/7 \rceilsevenths added
    826
    925
    1024
    1123
    1222
    1321
    1420
    Rounding up adds 6 sevenths at most, at 8 keys.

    why it is allowed: nn over 7 is a whole number of sevenths, so rounding it up adds at most 6 sevenths.

  5. the move: add the sevenths

    the line:
    n7+67=n+67\frac{n}{7} + \frac{6}{7} = \frac{n + 6}{7}

    why it is allowed: Sevenths add as whole things do, so 8 sevenths and 6 sevenths make 14 sevenths, which is 2.

  6. the move: put lines 4 and 5 in

    the line:
    C≤7(n+67−1)C \le 7\left(\frac{n + 6}{7} - 1\right)

    why it is allowed: Line 3 with n+67\frac{n + 6}{7} for ⌈n/7⌉\lceil n/7 \rceil, which by lines 4 and 5 is no smaller. So the right side can only grow, and CC is at most it: at 9 keys, 7 against 8.

  7. the move: multiply out

    the line:
    C≤n+6−7C \le n + 6 - 7

    why it is allowed: 7 times n+67\frac{n + 6}{7} is n+6n + 6, and 7 times 1 is 7.

  8. the move: 6 take away 7

    the line:
    C≤n−1C \le n - 1

    why it is allowed: 6−76 - 7 is −1-1.

  9. the move: and no more is needed

    the line:
    dealt round the 7 slots,no slot gets morethan ⌈n/7⌉\begin{gathered} \text{dealt round the 7 slots,} \\ \text{no slot gets more} \\ \text{than } \lceil n/7 \rceil \end{gathered}
    7140181512923103411451256136slotlanded where a key already was
    Keys 1 to 15 dealt by their remainders by 7. Slot 1 gets the most, 1, 8 and 15.

    why it is allowed: Deal 15 keys in turn: 1 to 7 one a slot, 8 to 14 one more each, then 15. That is 3 rounds, 15 over 7 rounded up, and a round gives a slot at most 1 key. Any nn keys take ⌈n/7⌉\lceil n/7 \rceil rounds alike.

  10. the move: read it

    the line:
    ⌈n/7⌉ keys, at least,in the fullest slot\begin{gathered} \lceil n/7 \rceil \text{ keys, at least,} \\ \text{in the fullest slot} \end{gathered}

    why it is allowed: By line 8, slots as line 2 says hold at most n−1n - 1 keys, so fewer than nn. So line 2 cannot be, and line 1 holds. By line 9 it is the least the fullest slot can be.

try it with a small nn: at n=8n = 8, line 3 gives C=7C = 7, which you can work out by hand

question 4Put nn keys in 7 slots, chained. How many looks does a look up for a key not there take, on average over the 7 slots?
  1. the move: the whole chain

    the line:
    a key not there is comparedwith every key in its slot\begin{gathered} \text{a key not there is compared} \\ \text{with every key in its slot} \end{gathered}
    slotkeys therelooks
    0351
    122, 15, 293
    291
    317, 31, 33
    4none0
    512, 40, 26, 334
    620, 482
    in all14 keys14
    The 14 keys of section 1, slot by slot.

    why it is allowed: None of them is the key, so it reads them all.

  2. the move: add the walks

    the line:
    add the 7 walks,divide by 7\begin{gathered} \text{add the 7 walks,} \\ \text{divide by 7} \end{gathered}

    why it is allowed: Each slot is as likely. At line 1 the looks add to 14, and 14 over 7 is 2.

  3. the move: every key in one chain

    the line:
    L=n7L = \frac{n}{7}

    why it is allowed: Let LL be the average walk. Each key is in exactly one chain, so the 7 walks add up to nn.

  4. the move: read it

    the line:
    the load:keys over slots\begin{gathered} \text{the load:} \\ \text{keys over slots} \end{gathered}

    why it is allowed: By line 3. With any number of slots the walks still add up to nn, so the average is nn over the slots, the load.

try it with a small nn: at n=14n = 14, line 3 gives L=2L = 2, which you can work out by hand

question 5Take nn keys and a key xx not among them, all from 0 to 28. Then pick a member at random. How many keys does the chain in xx's slot hold, on average?
  1. the move: sort the remainders

    the line:
    the remainders 0 to 28 in7 slots: 5 in slot 0,4 in each other slot\begin{gathered} \text{the remainders 0 to 28 in} \\ \text{7 slots: 5 in slot 0,} \\ \text{4 in each other slot} \end{gathered}
    remainders, sorted by slot07142128051815221429162324310172434411182544512192654613202764slotcount
    Remainders by slot.

    why it is allowed: Under a member, a key's remainder by 29 is 0 to 28, and that remainder's remainder by 7 is its slot.

  2. the move: pairs in one slot

    the line:
    5×4+6×(4×3)=925 \times 4 + 6 \times (4 \times 3) = 92

    why it is allowed: Two keys share a slot when their remainders do. So count pairs of different remainders in one slot, in order: 3 then 10, and 10 then 3, are two. Slot 3 holds 3, 10, 17 and 24, giving 4 times 3, 12.

  3. the move: every pair

    the line:
    29×28=81229 \times 28 = 812

    why it is allowed: Any two different remainders, in order, are 29, then 28 others.

  4. the move: the fact

    the line:
    29 divides no u×v,u and v from 1 to 28\begin{gathered} \text{29 divides no } u \times v \text{,} \\ u \text{ and } v \text{ from 1 to 28} \end{gathered}
    times1234
    11234
    22468
    336912
    4481216
    5 first: no product is 5, 10 or 15.

    why it is allowed: Divides means goes in exactly. Lines 5 to 9 prove it.

  5. the move: say it fails

    the line:
    say u works: 29 dividesu×v. Take u as smallas it can be, from 1 up\begin{gathered} \text{say } u \text{ works: 29 divides} \\ u \times v \text{. Take } u \text{ as small} \\ \text{as it can be, from 1 up} \end{gathered}

    why it is allowed: Pretend line 4 fails.

  6. the move: divide by u

    the line:
    29 is q×u+t, witht from 0 to u−1\begin{gathered} 29 \text{ is } q \times u + t \text{, with} \\ t \text{ from 0 to } u - 1 \end{gathered}

    why it is allowed: As question 1 does, with uu for 7: qq of them fit.

  7. the move: t works too

    the line:
    t×v is 29v−q×u×v,so 29 divides it\begin{gathered} t \times v \text{ is } 29v - q \times u \times v \text{,} \\ \text{so 29 divides it} \end{gathered}

    why it is allowed: Line 6 times vv, rearranged. 29 goes in 29v29v, and in q×u×vq \times u \times v by line 5, so in their gap.

  8. the move: t is 0

    the line:
    t is 0, so line 6 says29 is q×u: u divides 29\begin{gathered} t \text{ is 0, so line 6 says} \\ 29 \text{ is } q \times u \text{: } u \text{ divides 29} \end{gathered}

    why it is allowed: tt of 1 or more would work by line 7 and be under uu, the smallest.

  9. the move: no u works

    the line:
    u is 1 or 29, as 29 isa prime; neither can be u,so line 4 holds\begin{gathered} u \text{ is 1 or 29, as 29 is} \\ \text{a prime; neither can be } u \text{,} \\ \text{so line 4 holds} \end{gathered}

    why it is allowed: By line 8. uu is under 29, and 1 would need 29 to divide vv, which is 1 to 28.

  10. the move: never one remainder

    the line:
    ak1+b and ak2+bare a(k1−k2) apart\begin{gathered} a k_1 + b \text{ and } a k_2 + b \\ \text{are } a(k_1 - k_2) \text{ apart} \end{gathered}

    why it is allowed: Take a member, times aa, plus bb, and keys k1k_1 and k2k_2. Numbers leave one remainder by 29 only when a whole number of 29s apart, as 32 and 3. By line 4 these are not, as aa and k1−k2k_1 - k_2 are 1 to 28 in size. A minus sign changes nothing: 29 goes in minus 87 as in 87.

  11. the move: one pair from two members

    the line:
    (a−a′)k1+b−b′ and(a−a′)k2+b−b′ are 29s,so 29 divides (a−a′)(k1−k2)\begin{gathered} (a - a')k_1 + b - b' \text{ and} \\ (a - a')k_2 + b - b' \text{ are 29s,} \\ \text{so 29 divides } (a - a')(k_1 - k_2) \end{gathered}

    why it is allowed: Say times a′a', plus b′b' gives the same pair. Then each key's two numbers are a whole number of 29s apart, and so is the gap between those gaps.

  12. the move: so one member

    the line:
    a is a′, and thenb is b′\begin{gathered} a \text{ is } a' \text{, and then} \\ b \text{ is } b' \end{gathered}

    why it is allowed: Were a−a′a - a' not 0, line 4 would rule out line 11, as a−a′a - a' and k1−k2k_1 - k_2 are 1 to 28 in size. Then bb and b′b', both 0 to 28, leave one remainder by 29, so they are equal.

  13. the move: each pair once

    the line:
    812 members, 812 pairs:each pair of line 3 once\begin{gathered} \text{812 members, 812 pairs:} \\ \text{each pair of line 3 once} \end{gathered}
    each box: the remainders of 0 and 1 by 5× 1× 2× 3× 4+ 00, 10, 20, 30, 4+ 11, 21, 31, 41, 0+ 22, 32, 42, 02, 1+ 33, 43, 03, 13, 2+ 44, 04, 14, 24, 38 of the 20 put the two keys in one slot
    A smaller family, 5 for 29 and 2 slots: 20 members, 20 different pairs. 8 is 3 times 2, plus 2 times 1.

    why it is allowed: By lines 10 to 12, each member gives the two keys its own pair of different remainders.

  14. the move: why a prime

    the line:
    2×3=62 \times 3 = 6

    why it is allowed: With 6 for 29, times 2 takes the keys 0 and 3 to 0 and 6, one remainder by 6: 6 divides 2 times 3. Line 9 needs a prime.

  15. the move: so 92 of 812

    the line:
    two keys share a slotunder 92 of the 812 members\begin{gathered} \text{two keys share a slot} \\ \text{under 92 of the 812 members} \end{gathered}

    why it is allowed: By line 13, each of line 2's 92 pairs comes from one member, which puts the two keys, even 0 and 7, in one slot.

  16. the move: add the chances

    the line:
    E=92812+⋯+92812E = \frac{92}{812} + \dots + \frac{92}{812}

    why it is allowed: Every member is as likely, and xx is from 0 to 28 too, so by line 15 each key shares xx's slot with chance 92 over 812. Let EE be the nn chances added.

  17. the move: an average adds its chances

    the line:
    E=n×92812E = n \times \frac{92}{812}
    where does this come from?
    question 2 of the page expected costShuffle nn different numbers at random. How many pairs stand out of order, on average?
    1. the move: out of order half the time

      the line:
      a pair stands out of orderwith chance one half\begin{gathered} \text{a pair stands out of order} \\ \text{with chance one half} \end{gathered}
      in order1231322133 shufflesout of order3212313123 shuffles=
      Trading places 1 and 3 pairs each shuffle holding them in order with one holding them out of order, 3 and 3.
      shuffleplaces 1 and 2places 1 and 3places 2 and 3pairs out of order
      1, 2, 30
      1, 3, 2yes1
      2, 1, 3yes1
      2, 3, 1yesyes2
      3, 1, 2yesyes2
      3, 2, 1yesyesyes3
      in all3339
      Each shuffle of 1, 2 and 3, a yes where a pair of places is out of order. 9 over 6 is 1.5.

      why it is allowed: A pair is two places. Trading their numbers pairs each shuffle with another, and trading back undoes it. Each two has the pair out of order in exactly one, and both are as likely: chance one half.

    2. the move: expected counts add

      the line:
      the expected countadds up the chanceof every pair\begin{gathered} \text{the expected count} \\ \text{adds up the chance} \\ \text{of every pair} \end{gathered}

      why it is allowed: The table at line 1 adds two ways: down its last column, 9, and along its bottom row, 3 + 3 + 3. Over 6 shuffles, 9 over 6 is the average count, 1.5, and 3 over 6 three times is the pairs' chances added, 1.5 too. Both add the same yeses, so they agree for any nn, though the pairs depend on each other. With unequal chances, weight each yes by its order's chance. 2, 1, 3 at 3 over 4 and 1, 2, 3 at 1 over 4 give 3 over 4 both ways.

    3. the move: one half for each pair

      the line:
      one half timesthe number of pairs\begin{gathered} \text{one half times} \\ \text{the number of pairs} \end{gathered}

      why it is allowed: By line 2 the expected count adds line 1's one half once per pair.

    4. the move: count the pairs

      the line:
      P=12×((n−1)+⋯+1)P = \frac{1}{2} \times \bigl((n - 1) + \dots + 1\bigr)

      why it is allowed: Let PP be the expected count, by line 3 half the number of pairs. The first place pairs with the n−1n - 1 after it, the next with one fewer, down to 1. For 3 places, 2 + 1 is 3 pairs, so 1.5.

    5. the move: add them the other way round

      the line:
      P=12×(1+⋯+(n−1))P = \frac{1}{2} \times \bigl(1 + \dots + (n - 1)\bigr)

      why it is allowed: The same numbers in the other order.

    6. the move: use the page on adding up

      the line:
      P=12×(n−1)((n−1)+1)2P = \frac{1}{2} \times \frac{(n - 1)\bigl((n - 1) + 1\bigr)}{2}
      where does this come from?
      question 1 of the page adding up 1+2+⋯+n1 + 2 + \dots + nFit two staircases of squares together. What shape do they make?
      1. the move: draw the sum as a staircase

        the line:
        S=1+2+⋯+nS = 1 + 2 + \dots + n

        why it is allowed: Let SS be the sum of the whole numbers from 1 to nn. Draw it as a staircase, a column for each number: 1 square, then 2, and so on up to nn. For 5, columns of 1, 2, 3, 4 and 5 hold 15 squares.

      2. the move: take two staircases

        the line:
        2S=2(1+2+⋯+n)2S = 2(1 + 2 + \dots + n)

        why it is allowed: Two staircases hold twice the squares. Doubling both sides of line 1 keeps it true.

      3. the move: fit them into a rectangle

        the line:
        2S=n(n+1)2S = n(n + 1)
        Blue stands, yellow hangs. Two staircases of 1 to 5 squares fill a rectangle 5 wide and 6 tall, 30 squares. So 1 + 2 + 3 + 4 + 5 is 5 times 6, halved, which is 15.

        why it is allowed: Stand one staircase with its tallest column on the left. Hang the other upside down from the top, its tallest column on the right, as in the picture. The first column holds nn standing and 1 hanging. Each column to the right, the standing one loses a square and the hanging one gains one. So every column holds n+1n + 1, and the nn columns fill a rectangle nn wide and n+1n + 1 tall.

      4. the move: halve both sides

        the line:
        S=n(n+1)2S = \frac{n(n + 1)}{2}

        why it is allowed: Halving both sides of line 3 keeps it true and leaves one SS. For 5, half of 30 is 15.

      the whole page: adding up 1+2+⋯+n1 + 2 + \dots + n

      why it is allowed: The page on adding up 1 to nn adds the numbers from 1 to any whole number. They add up to that number times one more than it, halved: 1 + 2 + 3 is 3 times 4, halved, which is 6. In its working, its sum runs from 1 up to its own last number, which it calls nn. Here that is n−1n - 1.

    7. the move: tidy the bracket

      the line:
      P=12×(n−1)n2P = \frac{1}{2} \times \frac{(n - 1)n}{2}

      why it is allowed: (n−1)+1(n - 1) + 1 is nn.

    8. the move: multiply the halves

      the line:
      P=(n−1)n4P = \frac{(n - 1)n}{4}

      why it is allowed: Half of a half is a quarter. For 3, 2 times 3 over 4 is 1.5.

    9. the move: read it

      the line:
      half the pairs,on average\begin{gathered} \text{half the pairs,} \\ \text{on average} \end{gathered}

      why it is allowed: By lines 4 to 7 there are (n−1)n2\frac{(n - 1)n}{2} pairs, and line 8 is half that. For 3, 1.5, as line 1 counted.

    the whole page: expected cost

    why it is allowed: The nn chances are alike. The box under this line shows that an average count adds up each piece's chance, at its line 2. Each key is a piece, so EE is the average count in xx's slot.

  18. the move: 92 is under a seventh

    the line:
    E≤n×116812E \le n \times \frac{116}{812}

    why it is allowed: 812 over 7 is 116, and 92 is less.

  19. the move: tidy

    the line:
    E≤n7E \le \frac{n}{7}

    why it is allowed: 116 over 812 is 1 over 7.

  20. the move: read it

    the line:
    at most the load,whatever the keys\begin{gathered} \text{at most the load,} \\ \text{whatever the keys} \end{gathered}

    why it is allowed: By line 19. The five keys of section 1, all in slot 0 by the remainder by 7, give 5 times 92 over 812, about 0.57. Their load is 5 over 7, about 0.71.

try it with a small nn: at n=5n = 5, line 16 gives EE, about 0.57

a worked example

Put the words cab, bad, dab and bed in 7 slots, then look up bed and ace.

  1. cab, bad and dab go in slots 5, 3 and 2, as the working under the drawing shows.
  2. bed goes in slot 2, where dab is. A collision, so bed joins dab's chain, on top.
  3. Look up bed. Walk slot 2's chain from its oldest key, at the bottom, dab, then bed. Found in 2 looks.
  4. Look up ace. It goes 1, 29, 759, which is 108 sevens and 3 over, so slot 3. Compare with bad, the whole chain, so ace is not there, after 1 look.
0010dabbed22bad3140cab5160slotkeyswordrunning totalslotcab3, 79, 2,056= 293 × 7 + 55bad2, 53, 1,382= 197 × 7 + 33dab4, 105, 2,732= 390 × 7 + 22bed2, 57, 1,486= 212 × 7 + 22landed where a key already was
4 keys over 7 slots, a load of about 0.57.

the trap

check yourself

  1. Which slot does the key 45 go in, among 7?

    the answer

    Slot 3. 6 sevens, 42, fit in 45, and 3 is left over.

  2. Turn the word fig into a number, letter by letter in base 26, and find its slot among 7.

    the answer

    f, i and g are 6, 9 and 7. The total goes 6, 165, 4,297, which is 613 sevens and 6 over, so slot 6.

  3. 21 keys go in 7 slots. What is the load, and how many keys must the fullest slot hold, at least?

    the answer

    The load is 21 over 7, 3. By the pigeonhole question, the fullest holds at least 21 over 7 rounded up, 3.