Skip to content

Hash table with chaining

storing

Level 2 of 3

Also called Separate chaining.

test yourself

Six questions, four to pick from and two for paper. Each answer stays hidden until you open it.

fresh numbers: the questions a run answers, asked again on new numbers

choose one

question 1

An empty table of 5 buckets puts in 23, 41, 18, 33 and 6, in that order. How many looks do the five puts make in all?

the answer, and why

the answer is C

23 and 41 find empty buckets, 0 looks. 18 meets 23 in bucket 3, 1. 33 meets 23 and 18, 2. 6 meets 41 in bucket 1, 1. That is 4.

  1. step 9 of 16

    3341231801234

    33 leaves 3 when divided by 5, so it belongs in bucket 3.

    compared: 0

  2. step 10 of 16

    3341231801234

    23 is not 33.

    compared: 1

  3. step 11 of 16

    3341231801234

    18 is not 33.

    compared: 2

  4. step 12 of 16

    4123183301234

    33 is not in bucket 3 yet, so put it in.

    compared: 2

Operation 4 puts 33 in. Bucket 3 holds 23 and 18, so 2 looks. Yellow is being compared, red just put in.

if you chose another

  • That counts every number before each put, as if all shared one bucket.
  • That counts only 33's 2 looks, but 18 meets 23 and 6 meets 41 too.
  • That counts 1 look a put after the first two, but 33 meets two numbers.

question 2

Which five numbers, put into an empty table in this order, cost the fewest looks?

the answer, and why

the answer is D

11, 22, 33, 44 and 55 leave 1, 2, 3, 4 and 0, a bucket each, so no put meets a number. 0 looks.

55011111222133314441slotkeys
11, 22, 33, 44 and 55, one to a bucket.

if you chose another

  • All five leave 0 and share bucket 0, the dearest spread, 10 looks.
  • 12, 17 and 22 share bucket 2, and 3 and 8 share bucket 3, 4 looks.
  • 15, 25 and 35 share bucket 0, and 16 and 26 share bucket 1, 4 looks.

question 3

Which is true of this page's table, whose 5 buckets never grow?

the answer, and why

the answer is D

The average is (n−1)n10\frac{(n - 1)n}{10} looks, which section 4 squeezes between two multiples of n2n^2. The buckets never grow, so each chain grows with nn.

this tests where the formula comes from, on the learn page

if you chose another

  • That needs buckets that grow with the numbers. Here the next put at 1,000 numbers meets about 200.
  • Divide line 14 of section 4's spread-in-turn question by nn. The looks per number are at least n−9n - 9 over 10, 9.1 at 100 and 99.1 at 1,000. That passes any fixed number, so no fixed multiple of nn holds them.
  • For different numbers, the looks are the pairs sharing a bucket, which no order changes.

question 4

An empty table puts in 12, 7 and 32, takes 7 out, then puts in 22. How many looks do the five operations make?

the answer, and why

the answer is C

12 finds bucket 2 empty, 0. 7 meets 12, 1. 32 meets 12 and 7, 2. Taking 7 out meets 12, then finds 7, 2. 22 meets 12 and 32, 2. That is 7.

  1. step 11 of 19

    71273201234

    7 leaves 2 when divided by 5, so if it is here at all, it is in bucket 2.

    compared: 0

  2. step 12 of 19

    71273201234

    12 is not 7.

    compared: 1

  3. step 13 of 19

    71273201234

    Here is 7, in bucket 2.

    compared: 2

  4. step 14 of 19

    123201234

    Take 7 out of bucket 2.

    compared: 2

Operation 4 takes 7 out. It meets 12, then finds 7, 2 looks, and 7 leaves bucket 2. Yellow is being compared, and 7 is filled in when found.

if you chose another

  • That counts the take as a walk of the whole bucket, but it stops at 7.
  • That leaves out the take's 2 looks.
  • That counts the take as 1 look, but it meets 12 before it finds 7.

pen and paper

question 5about 8 minutes

Put 1 to 12 into an empty table of 5 buckets, in that order.

  1. Which bucket does each number go in?
  2. How many looks does each put make?
  3. Check your total against BB, line 5 of the spread-in-turn question.
a hint

Numbers 1 to 5 fill one round of buckets, 6 to 10 a second, and 11 and 12 start a third.

a worked answer

Puts 1 to 5 find empty buckets, 0 looks. Puts 6 to 10 each meet one number, 5 looks. 11 and 12 each meet two, 4 looks. That is 9 in all. The sum, for 12: five 0s, five 1s and two 2s, also 9.

putsbucketlooks each
1, 2, 3, 4, 51, 2, 3, 4, 00
6, 7, 8, 9, 101, 2, 3, 4, 01
11, 121, 22
in all9
Three rounds over the buckets. A put meets one number from each earlier round.
Why do 1 to nn, spread over the buckets in turn, cost the fewest looks, and how many?
  1. the move: a look is a pair

    the line:
    each pair sharing a bucketmakes exactly 1 look\begin{gathered} \text{each pair sharing a bucket} \\ \text{makes exactly 1 look} \end{gathered}
    0010712172333140slotkeyslanded where a key already was
    7, 12, 3 and 17 put in. Bucket 2 holds 7, 12 and 17, 3 pairs: 7 and 12, 7 and 17, 12 and 17. 12 makes 1 look and 17 makes 2. 3 shares its bucket with nothing.

    why it is allowed: By line 1 of the one-bucket question, a put compares its number with every number already in its bucket. So two numbers in one bucket meet once, when the later goes in. Two in different buckets never meet.

  2. the move: even out the sizes

    the line:
    swap a number in a bucketof size c for one landingin a bucket of size atmost c−2: a look saved\begin{gathered} \text{swap a number in a bucket} \\ \text{of size } c \text{ for one landing} \\ \text{in a bucket of size at} \\ \text{most } c - 2 \text{: a look saved} \end{gathered}
    1501107122233140slotkeyslanded where a key already was
    17 swapped for 15, which leaves 0. Bucket 2 drops to 7 and 12, 1 pair, and 15 shares bucket 0 with nothing.
    buckets 2 and 0 holdpairs in eachlooks
    3 and 03 and 03
    2 and 11 and 01
    Line 1's bucket 2 against bucket 2 after the swap. 17 leaves 2 pairs and joins none, so the swap saves 2 looks.

    why it is allowed: Swap 17 for 15. 17 met 7 and 12, so 2 pairs go; 15 lands in empty bucket 0, so none come: 2 looks saved, by line 1. In general, one fewer than cc pairs go and at most c−2c - 2 come.

  3. the move: the cheapest are even

    the line:
    the cheapest n numbers haveno two sizes 2 or more apart,as 1 to n do\begin{gathered} \text{the cheapest } n \text{ numbers have} \\ \text{no two sizes 2 or more apart,} \\ \text{as 1 to } n \text{ do} \end{gathered}
    001112712233832441slotkeyslanded where a key already was
    7 numbers with sizes 3, 2, 1, 1 and 0, largest first. 3 pairs in bucket 2 and 1 in bucket 3, 4 looks.
    50116122722331441slotkeyslanded where a key already was
    1 to 7, sizes 2, 2, 1, 1 and 1, largest first. 1 pair in bucket 1 and 1 in bucket 2, 2 looks, the fewest for 7 numbers.

    why it is allowed: If two sizes are 2 or more apart, line 2's swap saves a look, so that spread is not the cheapest. With no two sizes 2 or more apart, every size is qq or one more, where qq is nn over 5 rounded down. 5 buckets of qq hold 5q5q numbers, and the n−5qn - 5q left over make that many buckets one more. For 7, qq is 1, so 2 buckets hold 2 and 3 hold 1: 2 + 2 + 1 + 1 + 1 is 7. So all such spreads cost the same, by line 1, as 1 to 7 do.

  4. the move: price the kth put

    the line:
    spread in turn, the kth putmakes ⌊k−15⌋ looks\begin{gathered} \text{spread in turn, the } k\text{th put} \\ \text{makes } \lfloor \frac{k - 1}{5} \rfloor \text{ looks} \end{gathered}
    5100216111327122338324942slotkeyslanded where a key already was
    1 to 12 put in, in turn. 12 lands in bucket 2 and meets 2 and 7, 2 looks.

    why it is allowed: The k−1k - 1 numbers before it fill whole rounds of 5, one in each bucket, then part of a round. The part round fills only the buckets before its own in the turn 1, 2, 3, 4, 0. So its bucket holds one from each whole round. For 12, 11 over 5 is 2.2, rounded down 2: the 2 and the 7.

  5. the move: add the puts

    the line:
    B=⌊05⌋+⌊15⌋+⋯+⌊n−15⌋B = \lfloor \frac{0}{5} \rfloor + \lfloor \frac{1}{5} \rfloor + \dots + \lfloor \frac{n - 1}{5} \rfloor

    why it is allowed: BB is the looks of 1 to nn put in. By line 4, puts 1 to nn make ⌊05⌋\lfloor \frac{0}{5} \rfloor up to ⌊n−15⌋\lfloor \frac{n - 1}{5} \rfloor. For 10, five 0s and five 1s, 5.

  6. the move: count by rounds

    the line:
    B=5(0+1+⋯+(q−1))+ q (n−5q)\begin{gathered} B = 5\bigl(0 + 1 + \dots + (q - 1)\bigr) \\ + \, q\,(n - 5q) \end{gathered}
    putsroundlooks eachlooks
    1 to 5first00
    6 to 10second15
    11 and 12part of a third24
    in all9
    1 to 12 by rounds. Two whole rounds, so qq is 2, and 2 puts left over.

    why it is allowed: Let qq be the whole rounds of 5 puts, nn over 5 rounded down. In line 5, the rounds add 0, then 1, and on up to q−1q - 1, five times each. The n−5qn - 5q puts left over add qq each. For 12, qq is 2: 5 times 1, plus 2 times 2, is 9.

  7. the move: use the page on adding up

    the line:
    B=5(q−1)q2+q (n−5q)B = \frac{5(q - 1)q}{2} + q\,(n - 5q)
    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 box under this line shows that 1 up to a last number adds to that number times one more, halved. Here the last number is q−1q - 1, and the 0 adds nothing: q−1q - 1 times qq, halved, five times. For 12, 5 times 1, plus 4, is 9.

  8. the move: drop the rounding

    the line:
    B≤0+1+⋯+(n−1)5B \le \frac{0 + 1 + \dots + (n - 1)}{5}

    why it is allowed: Line 7's qq is awkward beside n2n^2, so for how fast BB grows, go back to line 5. Rounding down never makes a number bigger. Fifths add their tops: 0 fifths, 1 fifth and 2 fifths make 3 fifths. For 10, 5 is at most 45 over 5, which is 9.

  9. the move: use the page on adding up

    the line:
    B≤(n−1)n10B \le \frac{(n - 1)n}{10}
    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 same box, with last number n−1n - 1: line 8's top is (n−1)n2\frac{(n - 1)n}{2}, and a fifth of that is (n−1)n10\frac{(n - 1)n}{10}. For 10, 9.

  10. the move: a ceiling

    the line:
    B≤n210B \le \frac{n^2}{10}

    why it is allowed: In line 9, n−1n - 1 is less than nn. For 10, 9 is at most 10.

  11. the move: read it as a bound

    the line:
    B∈O(n2)B \in O(n^2)

    why it is allowed: By line 10, with the fixed multiple a tenth.

  12. the move: rounding down loses at most 4 fifths

    the line:
    B≥0+1+⋯+(n−1)5−4n5B \ge \frac{0 + 1 + \dots + (n - 1)}{5} - \frac{4n}{5}
    toptop over 5rounded downlost
    5110
    61.210.2
    71.410.4
    81.610.6
    91.810.8
    Rounding a fifth down loses 0, 1, 2, 3 or 4 fifths, never more.

    why it is allowed: Each of line 5's nn pieces is its fifth, less what rounding down loses, at most 4 fifths. So nn pieces lose at most nn times 4 fifths. For 10, 5 is at least 9 less 8.

  13. the move: the same sum

    the line:
    B≥(n−1)n10−4n5B \ge \frac{(n - 1)n}{10} - \frac{4n}{5}

    why it is allowed: Line 12's sum is line 8's, which line 9 found to be (n−1)n10\frac{(n - 1)n}{10}. For 10, 9 less 8, which is 1.

  14. the move: tidy

    the line:
    B≥n(n−9)10B \ge \frac{n(n - 9)}{10}

    why it is allowed: In line 13, 4 fifths of nn is 8 tenths of nn. Take nn out of both tenths: nn times (n−1)(n - 1), less nn times 8, is nn times (n−9)(n - 9). For 20, 20 times 11 over 10 is 22, and BB is 30.

  15. the move: read it as a bound

    the line:
    B∈Ω(n2)B \in \Omega(n^2)
    looksnumbers put in050100150200010203040looksnumbers put in050100150200010203040
    • the ceiling, a tenth of n2n^2
    • BB, spread in turn
    • the floor, a twentieth of n2n^2
    From 18 numbers on, BB stays between a twentieth and a tenth of n2n^2. At 40, 140 lies between 80 and 160.

    why it is allowed: By line 14. From 18 numbers on, 9 is at most half of nn, so n−9n - 9 is at least half of nn. Then BB is at least a twentieth of n2n^2, the fixed multiple. At 20, 30 is at least 20.

  16. the move: ceiling and floor together

    the line:
    B∈Θ(n2)B \in \Theta(n^2)

    why it is allowed: Lines 11 and 15 bound BB by the same growth, n2n^2.

try it with a small nn: at n=10n = 10, line 5 gives B=5B = 5, which you can work out by hand

this tests where the formula comes from, on the learn page

what a full answer includes
  • Buckets 1, 2, 3, 4, 0 in turn.
  • Looks 0 five times, 1 five times, 2 twice: 9.
  • The sum giving 9 at 12.

question 6about 8 minutes

Put 3 numbers into an empty table of 5 buckets, each landing in a bucket picked at random. Each of the 125 ways, 5 times 5 times 5, is as likely.

  1. How many looks does the second put make, on average?
  2. And the third?
  3. Add them, and check against (n−1)n10\frac{(n - 1)n}{10} at 3.
a hint

A put makes a look for each number already in its bucket, and its bucket is any of the 5.

a worked answer

The second put meets the first only when it lands in the first's bucket, 1 of the 5: 1 over 5 on average. The third's 5 buckets hold the 2 numbers already in, 2 over 5. Together 3 over 5, 0.6. The formula gives 2 times 3 over 10, also 0.6.

putnumbers already inlooks on average
100
211 over 5
322 over 5
in all3 over 5
Each put averages the numbers already in over the 5 buckets, the load.
Why do numbers landing at random cost (n−1)n10\frac{(n - 1)n}{10} looks on average?
  1. the move: average one put over its bucket

    the line:
    the kth put makes,on average, k−15looks: the load\begin{gathered} \text{the } k\text{th put makes,} \\ \text{on average, } \frac{k - 1}{5} \\ \text{looks: the load} \end{gathered}
    the third number lands innumbers therelooks
    bucket 0none0
    bucket 1none0
    bucket 2271
    bucket 3131
    bucket 4none0
    on average2 over 5
    13 and 27 are in. The third number's 5 buckets make 2 looks in all, 2 over 5 on average, numbers over buckets.

    why it is allowed: Its bucket is any of the 5, each as likely, so average its looks over the 5. By line 1 of the one-bucket question, each bucket's looks are the numbers there. Wherever the k−1k - 1 numbers already in went, the 5 buckets hold k−1k - 1 in all. Had 13 and 28 shared bucket 3, it would give 2 and the rest 0: still 2 over 5.

  2. the move: add the puts' averages

    the line:
    A=05+15+⋯+n−15A = \frac{0}{5} + \frac{1}{5} + \dots + \frac{n - 1}{5}

    why it is allowed: By line 1, whatever the earlier numbers did, puts 1 to nn average 0 up to n−1n - 1 over 5. Let AA be these averages added. For 3, 3 over 5.

  3. the move: an average adds its pieces

    the line:
    the average looks in all=05+15+⋯+n−15=A\begin{gathered} \text{the average looks in all} \\ = \frac{0}{5} + \frac{1}{5} + \dots + \frac{n - 1}{5} = A \end{gathered}
    buckets of 3 numbersput 2's looksput 3's lookslooks in all
    0, 0, 0123
    0, 0, 1101
    0, 1, 0011
    0, 1, 1011
    1, 0, 0011
    1, 0, 1011
    1, 1, 0101
    1, 1, 1123
    on average1 over 213 over 2
    3 numbers into 2 buckets, all 8 choices. Put 2 averages 1 over 2 and put 3 averages 1, the load before each. The totals average 3 over 2, their sum.
    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 box under this line shows that an average count adds up each piece's chance, at its line 2. Count the kkth put's looks as one piece for each number already in, a yes when they share a bucket, with chance 1 over 5. Its pieces add to line 1's average, so AA is the looks averaged over every choice of buckets. The table shows it on 2 buckets, 8 rows, where 5 buckets would need 125.

  4. the move: take out the fifth

    the line:
    A=0+1+⋯+(n−1)5A = \frac{0 + 1 + \dots + (n - 1)}{5}

    why it is allowed: Fifths add their tops, as 0 fifths, 1 fifth and 2 fifths make 3 fifths.

  5. the move: use the page on adding up

    the line:
    A=(n−1)n10A = \frac{(n - 1)n}{10}
    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 box under this line shows that 1 up to a last number adds to that number times one more, halved. Here the last number is n−1n - 1, so this question's line 4 has (n−1)n2\frac{(n - 1)n}{2} on top, and a fifth of that is (n−1)n10\frac{(n - 1)n}{10}. For 3, 2 times 3 over 10 is 0.6.

  6. the move: a ceiling

    the line:
    A≤n210A \le \frac{n^2}{10}

    why it is allowed: In line 5, n−1n - 1 is less than nn. For 3, 0.6 is at most 0.9.

  7. the move: read it as a bound

    the line:
    A∈O(n2)A \in O(n^2)

    why it is allowed: By line 6.

  8. the move: a floor

    the line:
    A≥n220 for n≥2A \ge \frac{n^2}{20} \text{ for } n \ge 2

    why it is allowed: In line 5, write half of nn in place of n−1n - 1, no bigger from 2 numbers on by line 10 of the one-bucket question. Half of nn times nn, over 10, is n220\frac{n^2}{20}. For 3, 0.6 is at least 0.45.

  9. the move: read it as a bound

    the line:
    A∈Ω(n2)A \in \Omega(n^2)

    why it is allowed: By line 8, from 2 numbers on.

  10. the move: ceiling and floor together

    the line:
    A∈Θ(n2)A \in \Theta(n^2)

    why it is allowed: Lines 7 and 9 bound AA by the same growth, n2n^2. At random costs little more than spread in turn, 990 looks against 950 at 100 numbers.

try it on small inputs: over every choice of bucket for each of 3 numbers, 125 in all, the average is A=0.6A = 0.6

this tests where the formula comes from, on the learn page

what a full answer includes
  • The second put, 1 over 5.
  • The third, 2 over 5.
  • In all 0.6, the formula at 3.