Skip to content

Linked list

storing

Level 1 of 3

Also called Sorted singly linked list.

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 chain kept in order puts in 30, 12 and 45, takes 12 out, then puts in 20. What does the chain hold then, from the start?

the answer, and why

the answer is B

After 12 leaves, the chain holds 30, 45. 30 is bigger than 20, so the first look stops the walk and 20 goes in at the start.

  1. step 10 of 12

    30145

    30 is bigger than 20, so 20 goes just before it.

    looks so far: 1

  2. step 11 of 12

    2030145

    Link 20 in at the start of the chain.

    looks so far: 1

  • the start, holding no number
  • a look, numbered in turn
  • looked at now
  • just linked in, with its new pointers
Operation 5 puts 20 in, after operations 1 to 4 put in 30, 12 and 45 and took 12 out. 30 is bigger than 20, so 20 is linked in at the start.

if you chose another

  • That keeps 12, but the fourth operation takes 12 out.
  • That puts 20 at the end, but a put stops at the first bigger number, 30.
  • That loses 30. Taking 12 out links the start to 30, which stays.

question 2

Starting from an empty chain kept in order, you put in 24, 9, 31 and 17, in that order. How many looks do the four puts make in all?

the answer, and why

the answer is A

24 finds the chain empty, 0 looks. 9 stops at 24, 1. 31 passes 9 and 24, 2. 17 passes 9 and stops at 24, 2. That is 5.

  1. step 8 of 11

    912431

    9 is not bigger than 17, so walk on past it.

    looks so far: 1

  2. step 9 of 11

    9124231

    24 is bigger than 17, so 17 goes just before it.

    looks so far: 2

  3. step 10 of 11

    911724231

    Link 17 in just before 24, and point it at 24.

    looks so far: 2

  • the start, holding no number
  • a look, numbered in turn
  • looked at now
  • looked at, and walked past
  • just linked in, with its new pointers
Operation 4 puts 17 in, after operations 1 to 3 put in 24, 9 and 31. It passes 9, stops at 24 and links 17 in between, 2 looks.

if you chose another

  • That counts every place each time, as smallest first would, 0 + 1 + 2 + 3.
  • That misses a look. 31 passes both 9 and 24 to reach the end.
  • That counts 1 look a put after the first, as biggest first would.

question 3

Which order of putting 14, 26, 38 and 51 into an empty chain costs the fewest looks?

the answer, and why

the answer is A

Biggest first, each put after the first stops at its first look. 0 + 1 + 1 + 1 is 3.

  1. step 7 of 9

    2613851

    26 is bigger than 14, so 14 goes just before it.

    looks so far: 1

  2. step 8 of 9

    142613851

    Link 14 in at the start of the chain.

    looks so far: 1

  • the start, holding no number
  • a look, numbered in turn
  • looked at now
  • just linked in, with its new pointers
Biggest first, operation 4 puts 14 in, after 51, 38 and 26 went in. 26 is bigger than 14, so one look, and 14 goes in at the start.

if you chose another

  • That costs 5. 38 passes 14 and 26 before it stops at 51.
  • Smallest first is the dearest order, 0 + 1 + 2 + 3, which is 6.
  • That costs 5. 51 passes both numbers before it to reach the end.

question 4

Sebastian Bourges' books put shuffled numbers in order one at a time, in a chain and in a row, each put scanning from the front (volume two, chapter 22). Which is true?

the answer, and why

the answer is B

Section 4's row question counts the row at about twice the chain from about 100 numbers on. The clock still favoured the row: each read of a chain waits for the pointer before it.

address01234567a rowa chainwait 191142263314wait 114319126wait 214231926wait 314319263wait 414314926
  • read in this wait, numbered in turn
  • not read yet
  • read in an earlier wait
  • other memory
  • a pointer read, giving the next address
  • read at once, every address known ahead
The same 4 numbers, read from a row all at once, and from a chain one wait a read. The next address is known only when the read before it ends.

this tests how it compares, on the learn page

if you chose another

  • A chain has no middle to jump to. Its places are reached only from the start.
  • Θ(n2)\Theta(n^2) says how a count grows, not how long each look takes.
  • A put into the row moves every bigger number one slot along.

pen and paper

question 5about 6 minutes

Put 4, 11, 19, 26, 33 and 47 into an empty chain kept in order, in that order.

  1. How many looks does each put make?
  2. How many in all?
  3. Check your total against (n−1)n2\frac{(n - 1)n}{2}, the formula of section 4.
a hint

Each new number is bigger than all before it, so it passes every place.

a worked answer

The puts make 0, 1, 2, 3, 4 and 5 looks, as each passes every number already in. That is 15 in all. With 6 numbers, 5 times 6, halved, is 15.

putchain beforelooks
4empty0
1141
194, 112
264, 11, 193
334, 11, 19, 264
474, 11, 19, 26, 335
in all15
Each put passes the whole chain and links its number at the end.
Why do nn numbers put in smallest first cost (n−1)n2\frac{(n - 1)n}{2} looks, the most any order can?
  1. the move: price one put

    the line:
    a put into a chainof m numbers makesat most m looks\begin{gathered} \text{a put into a chain} \\ \text{of } m \text{ numbers makes} \\ \text{at most } m \text{ looks} \end{gathered}
    1. step 8 of 12

      311629

      3 is not bigger than 40, so walk on past it.

      looks so far: 1

    2. step 9 of 12

      3116229

      16 is not bigger than 40, so walk on past it.

      looks so far: 2

    3. step 10 of 12

      31162293

      29 is not bigger than 40, so walk on past it.

      looks so far: 3

    4. step 11 of 12

      3116229340

      Link 40 in at the end of the chain.

      looks so far: 3

    • the start, holding no number
    • a look, numbered in turn
    • looked at now
    • looked at, and walked past
    • just linked in, with its new pointers
    Operation 4 puts 40 in, after 3, 16 and 29 went in, smallest first. 40 is bigger than all three, so the walk passes them and links 40 at the end. 3 looks.

    why it is allowed: Here mm is how many numbers the chain holds. The walk looks at each place once, from the start, and stops at the first bigger number or at the end.

  2. the move: smallest first, every place

    the line:
    smallest first, the kth putmakes k−1 looks\begin{gathered} \text{smallest first, the } k\text{th put} \\ \text{makes } k - 1 \text{ looks} \end{gathered}

    why it is allowed: Each new number is bigger than all before it, so no place stops the walk: the kkth put passes all k−1k - 1 numbers. Four 24s cost the same, 0 + 1 + 2 + 3, as no 24 stops the walk. For 4, the fourth put makes 3.

  3. the move: no order costs more

    the line:
    in any order, the kthput makes at mostk−1 looks\begin{gathered} \text{in any order, the } k\text{th} \\ \text{put makes at most} \\ k - 1 \text{ looks} \end{gathered}

    why it is allowed: The kkth put meets the k−1k - 1 numbers already in, so by line 1 it makes at most k−1k - 1 looks. So no order costs more than line 2's.

  4. the move: add the puts

    the line:
    W=0+1+2+⋯+(n−1)W = 0 + 1 + 2 + \dots + (n - 1)

    why it is allowed: WW is the looks of nn numbers put in smallest first. By line 2, puts 1 to nn make 0, 1, and on up to n−1n - 1. For 4, 0 + 1 + 2 + 3 is 6.

  5. the move: leave out the 0

    the line:
    W=1+2+⋯+(n−1)W = 1 + 2 + \dots + (n - 1)

    why it is allowed: Line 4 without its 0, as adding 0 changes nothing.

  6. the move: use the page on adding up

    the line:
    W=(n−1)((n−1)+1)2W = \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 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. For 4, 1 + 2 + 3 is 3 times 4, halved, which is 6.

  7. the move: tidy

    the line:
    W=(n−1)n2W = \frac{(n - 1)n}{2}

    why it is allowed: In line 6, (n−1)+1(n - 1) + 1 is nn. For 5, 4 times 5, halved, is 10.

  8. the move: a ceiling

    the line:
    W≤n22W \le \frac{n^2}{2}

    why it is allowed: In line 7, n−1n - 1 is less than nn, so (n−1)n(n - 1)n is at most nn times nn. For 5, 10 is at most 12.5.

  9. the move: read it as a bound

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

    why it is allowed: By line 8, with the fixed multiple one half.

  10. the move: a fact about n

    the line:
    n−1≥n2 for n≥2n - 1 \ge \frac{n}{2} \text{ for } n \ge 2

    why it is allowed: Taking 1 from nn takes at most half of it once nn is 2 or more. For 5, 4 is at least 2.5.

  11. the move: a floor

    the line:
    W≥n24 for n≥2W \ge \frac{n^2}{4} \text{ for } n \ge 2

    why it is allowed: In line 7, put line 10's half of nn for n−1n - 1, which is no bigger. Half of nn times nn, halved, is a quarter of n2n^2. For 5, 10 is at least 6.25.

  12. the move: read it as a bound

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

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

  13. the move: ceiling and floor together

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

    why it is allowed: Lines 9 and 12 bound WW by the same growth, n2n^2.

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

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

what a full answer includes
  • 0 to 5 looks, one for each number already in.
  • 15 in all.
  • The formula giving 15 at 6.

question 6about 10 minutes

Put 7, 15 and 22 into an empty chain kept in order, in an order picked at random, each of the 6 orders as likely.

  1. Count the looks of each order.
  2. Average them.
  3. Check your average against (n−1)n4+n−H(n)\frac{(n - 1)n}{4} + n - H(n) at 3.
a hint

The second put always makes 1 look. The third makes 1 look when it is the smallest, and 2 otherwise.

a worked answer

Four orders cost 3 looks and two cost 2: 16 in all, and 16 over 6 is about 2.67. In the formula, 2 times 3 over 4 is 1.5, and H(3)H(3) is 1 + 1 over 2 + 1 over 3, 11 over 6. In sixths, 1.5, 3 and H(3)H(3) are 9, 18 and 11, and 9 + 18 less 11 is 16: 16 over 6 too.

orderlooks by each putlooks
7, 15, 220, 1, 23
7, 22, 150, 1, 23
15, 7, 220, 1, 23
15, 22, 70, 1, 12
22, 7, 150, 1, 23
22, 15, 70, 1, 12
in all16
on average16 over 6, about 2.67
The 6 orders of 7, 15 and 22. The two that put 7 last cost 2.
Why do shuffled numbers cost (n−1)n4+n−H(n)\frac{(n - 1)n}{4} + n - H(n) looks on average?
  1. the move: price one put by what it passes

    the line:
    a put makes 1 lookfor each smaller numberalready in, and 1 moreunless it is a new best\begin{gathered} \text{a put makes 1 look} \\ \text{for each smaller number} \\ \text{already in, and 1 more} \\ \text{unless it is a new best} \end{gathered}
    1. step 8 of 11

      812033

      8 is not bigger than 14, so walk on past it.

      looks so far: 1

    2. step 9 of 11

      8120233

      20 is bigger than 14, so 14 goes just before it.

      looks so far: 2

    3. step 10 of 11

      811420233

      Link 14 in just before 20, and point it at 20.

      looks so far: 2

    • the start, holding no number
    • a look, numbered in turn
    • looked at now
    • looked at, and walked past
    • just linked in, with its new pointers
    Operation 4 puts 14 in, after 20, 8 and 33 went in. It passes 8, the one smaller number, then looks at 20 and stops. 1 + 1 is 2 looks.

    why it is allowed: The numbers are all different. The walk passes every smaller number, then stops at the first bigger one. A new best, bigger than all before it, finds none to stop at.

  2. the move: add over the puts

    the line:
    the looks are thepairs in order, plus n,less the new bests\begin{gathered} \text{the looks are the} \\ \text{pairs in order, plus } n, \\ \text{less the new bests} \end{gathered}
    putsmaller numbers passedplus 1less 1 for a new bestlooks
    20110
    31111
    10101
    in all1322
    Putting in 2, 3, then 1. Each put's looks are the smaller numbers it passes, plus 1, less 1 for a new best.

    why it is allowed: Line 1, added over the nn puts. Each smaller number a put passes makes one pair in order, the smaller put in first. On 2, 3, 1: 1 pair in order, plus 3, less 2 new bests, is 2.

  3. the move: average piece by piece

    the line:
    A=average pairsin order+n−average new bests\begin{gathered} A = \text{average pairs} \\ \text{in order} + n \\ - \text{average new bests} \end{gathered}
    order put inpairs in ordernew bestslooks
    1, 2, 3333
    1, 3, 2223
    2, 1, 3223
    2, 3, 1122
    3, 1, 2113
    3, 2, 1012
    in all91116
    Each order of 1, 2 and 3. Its looks are its pairs in order, plus 3, less its new bests. In all, 9 + 18 less 11 is 16, and the 18 is 3 for each of the 6 orders.

    why it is allowed: AA is the looks averaged over every order of nn different numbers. By line 2, each order's looks are its pairs in order, plus nn, less its new bests. Averages add piece by piece: add each piece over every order, then divide by how many orders there are. For 3, 9 over 6 + 3 less 11 over 6, which is 16 over 6.

  4. the move: use the page on expected cost

    the line:
    A=(n−1)n4+n−average new bests\begin{gathered} A = \frac{(n - 1)n}{4} + n \\ - \text{average new bests} \end{gathered}
    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: There are 1 + 2 + ... + (n−1)(n - 1) pairs, each in order in half the orders. Line 3's table holds 9 in order over the 6 orders, and the box's table 9 out of order. So both average the same, (n−1)n4\frac{(n - 1)n}{4}, which the box works out. For 3, 9 over 6 is 1.5.

  5. the move: use the page on expected cost again

    the line:
    A=(n−1)n4+n−(1+12+13+⋯+1n)\begin{gathered} A = \frac{(n - 1)n}{4} + n \\ - \Bigl(1 + \frac{1}{2} + \frac{1}{3} + \dots + \frac{1}{n}\Bigr) \end{gathered}
    where does this come from?
    question 3 of the page expected costWalk along nn different numbers shuffled at random. How many new bests turn up, on average?
    1. the move: a new best at place k

      the line:
      place k holds a new bestwith chance 1 over k\begin{gathered} \text{place } k \text{ holds a new best} \\ \text{with chance 1 over } k \end{gathered}
      3 at place 13213122 shuffles3 at place 31232132 shuffles=3 at place 21322312 shuffles=
      Trading place 3 with place 1 or 2 moves the 3 there, and trading back undoes it. 2 shuffles hold the 3 at each place.
      shuffleplace 1place 2place 3new bests
      1, 2, 3yesyesyes3
      1, 3, 2yesyes2
      2, 1, 3yesyes2
      2, 3, 1yesyes2
      3, 1, 2yes1
      3, 2, 1yes1
      in all63211
      Each shuffle of 1, 2 and 3, a yes where a place holds a new best. 11 over 6 is 1 + 1 over 2 + 1 over 3.

      why it is allowed: The number at place kk is a new best when it is the biggest of the first kk. Trade place kk with another of the first kk: a biggest at one moves to the other, and trading back undoes it. So it stands equally often at each of the first kk places: at place kk in 1 of every kk shuffles. For 3, the 3 stands at each place in 2 of 6.

    2. the move: add the chances

      the line:
      R=1+12+13+⋯+1nR = 1 + \frac{1}{2} + \frac{1}{3} + \dots + \frac{1}{n}

      why it is allowed: Let RR be the expected new bests. Each place is a piece, a new best or not. By line 2 of question 2 of the page expected cost, RR adds their chances: 1 over kk for place kk, by line 1.

    3. the move: read it

      the line:
      the harmonic sum\begin{gathered} \text{the harmonic sum} \end{gathered}

      why it is allowed: By line 2, the harmonic sum. For 3, 11 over 6, about 1.83, as line 1 counted.

    the whole page: expected cost

    why it is allowed: The kkth put is a new best with chance 1 over kk, and the chances add: the box under this line shows both. For 3, 1 + 1 over 2 + 1 over 3 is 11 over 6, line 3's.

  6. the move: name the harmonic sum

    the line:
    A=(n−1)n4+n−H(n)A = \frac{(n - 1)n}{4} + n - H(n)

    why it is allowed: Line 5's bracket is the harmonic sum, H(n)H(n). For 3, about 1.83, so AA is about 2.67, line 3's 16 over 6.

  7. the move: a ceiling from the dearest order

    the line:
    A≤(n−1)n2A \le \frac{(n - 1)n}{2}

    why it is allowed: No order costs more than smallest first, by the smallest-first question's line 3 and its line 7. So neither does the average. For 3, 2.67 is at most 3.

  8. the move: a simpler ceiling

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

    why it is allowed: As in the smallest-first question's line 8, (n−1)n(n - 1)n is at most nn times nn. For 3, 2.67 is at most 4.5.

  9. the move: read it as a bound

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

    why it is allowed: By line 8.

  10. the move: a floor

    the line:
    A≥(n−1)n4A \ge \frac{(n - 1)n}{4}

    why it is allowed: H(n)H(n) adds nn numbers, each at most 1, so in line 6 nn less H(n)H(n) is at least 0. For 3, 2.67 is at least 1.5.

  11. the move: a simpler floor

    the line:
    A≥n28 for n≥2A \ge \frac{n^2}{8} \text{ for } n \ge 2

    why it is allowed: In line 10, put half of nn for n−1n - 1, which is no bigger by the smallest-first question's line 10. For 4, line 10's 3 is at least 2.

  12. the move: read it as a bound

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

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

  13. the move: ceiling and floor together

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

    why it is allowed: Lines 9 and 12 bound AA by the same growth, n2n^2. At 1,000 numbers, H(n)H(n) is about 7.5, beside about 250,000 pairs in order on average, of 499,500 pairs.

try it on small inputs: over every order of 3 numbers put in, the average AA is about 2.67

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

what a full answer includes
  • Four orders at 3 looks, two at 2.
  • The average, 16 over 6, about 2.67.
  • The formula giving 16 over 6 too.