Skip to content

the sorting floor

why it works

what it is

A comparing sort with no random choices takes at least 5 comparisons on its worst row of 4 different numbers.

A comparing sort learns about different numbers only by asking of two, 'is the first bigger?'. Take one with no random choices, always doing the same on the same row. 3 numbers stand in 6 orders. Two orders moved alike end differently, so it must tell all 6 apart by its answers. Each answer doubles the possible answer lists.

3 2 13 1 22 1 32 3 11 3 21 2 3yesno
Bubble sort's answers to 'is the left bigger?' on 1, 2 and 3: each line down one answer, each path one list. 2 answers reach only 4 ends, too few for 6 orders.
in order123out of order132
Swapping the last two takes each row to the other: 1, 3, 2 ends in order, 1, 2, 3 does not.

So its worst row of 3, the order costing it most, takes at least 3 comparisons: the sorting floor for 3. 4 numbers stand in 4 × 3 × 2 × 1, 24 orders; 4 answers make 16 lists and 5 make 32, so the floor for 4 is 5. Four doublings of 1 make 16, so the log to base 2 of 16 is 4. 24 lies between 16 and 32, so its log lies between 4 and 5, about 4.58.

numberlog× 2+ 11021428316432562.58244.58
Each step right doubles. The log of 6, about 2.58, rounds up to 3, the floor for 3; that of 24, about 4.58, to 5, the floor for 4.

For nn numbers, from 2, the floor is ⌈log⁡2 n!⌉\lceil \log_2\, n! \rceil, the log of the n!n! orders rounded up; n!n! is read nn factorial. It grows like n log⁡2 nn \,\log_2\, n (questions 4 and 5), nn times the log of nn, so every such sort's worst row grows at least that fast.

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 1In how many orders can nn different numbers stand?
  1. the move: the first place

    the line:
    the first place takesany of the n numbers\begin{gathered} \text{the first place takes} \\ \text{any of the } n \text{ numbers} \end{gathered}

    why it is allowed: Any of the nn numbers can stand first, so any of 3 for 1, 2 and 3.

  2. the move: the second place

    the line:
    each first choice goes onin n−1 ways\begin{gathered} \text{each first choice goes on} \\ \text{in } n - 1 \text{ ways} \end{gathered}
    firstsecondthird
    123
    132
    213
    231
    312
    321
    The 6 orders of 1, 2 and 3, place by place.

    why it is allowed: From 2 numbers on, each first choice leaves n−1n - 1 for the second place. For 1, 2 and 3, 3 times 2 is 6, and the number left fills the third.

  3. the move: on to the last

    the line:
    R=n×(n−1)×⋯×1R = n \times (n - 1) \times \dots \times 1

    why it is allowed: Let RR be the number of orders. As in line 2, each place has one choice fewer, down to 1, and the choices multiply. For 3, 3 × 2 × 1 is 6.

  4. the move: n factorial

    the line:
    R=n!R = n!

    why it is allowed: nn down to 1, multiplied, is written n!n!, read nn factorial.

  5. the move: read it

    the line:
    each number more multipliesthe orders\begin{gathered} \text{each number more multiplies} \\ \text{the orders} \end{gathered}

    why it is allowed: By line 3, one number more adds a factor. 3 numbers stand in 6 orders, 4 in 24 and 5 in 120.

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

question 2How many different lists of nn yes-or-no answers are there?
  1. the move: two answers

    the line:
    each answer isyes or no\begin{gathered} \text{each answer is} \\ \text{yes or no} \end{gathered}

    why it is allowed: Here nn counts answers, not numbers. Each comparison answers yes or no.

  2. the move: each answer doubles

    the line:
    each list goes onas a yes or as a no\begin{gathered} \text{each list goes on} \\ \text{as a yes or as a no} \end{gathered}
    answersthe listshow many
    0the empty list1
    1yes; no2
    2yes yes; yes no; no yes; no no4
    Each answer more doubles the lists, 1, 2, 4.

    why it is allowed: Each list goes on with a yes or a no, so each answer doubles the lists. No answers make one list, the empty one.

  3. the move: double n times

    the line:
    A=2×2×⋯×2A = 2 \times 2 \times \dots \times 2

    why it is allowed: Let AA be the number of lists of nn answers. By line 2, 1 doubled nn times. For 3, 2 × 2 × 2 is 8.

  4. the move: a power

    the line:
    A=2nA = 2^n

    why it is allowed: nn 2s multiplied are written 2n2^n, read 2 to the power nn. 2 to the power 0 is 1.

  5. the move: read it

    the line:
    each question more doublesthe lists\begin{gathered} \text{each question more doubles} \\ \text{the lists} \end{gathered}

    why it is allowed: By line 4, one answer more is one 2 more: 4 answers make 16 lists and 5 make 32.

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

question 3At least how many comparisons does a comparing sort's worst row of nn different numbers take?
  1. the move: answers decide

    the line:
    two rows that givethe same answersare treated the same\begin{gathered} \text{two rows that give} \\ \text{the same answers} \\ \text{are treated the same} \end{gathered}
    the rowanswersmovesit ends as
    1, 3, 2no yes noswap the last two1, 2, 3
    10, 30, 20no yes noswap the last two10, 20, 30
    Bubble sort walks left to right, asking each pair of neighbours 'is the left bigger?' and swapping on a yes. Each walk is one pair shorter, until one swaps nothing or no pair is left.

    why it is allowed: A comparing sort with no random choices learns only from its answers, so its next comparison and move hang only on its answers so far. So rows giving the same answers get the same comparisons and moves, and stop together.

  2. the move: one list per order

    the line:
    two orders of the same numbersget different answer lists\begin{gathered} \text{two orders of the same numbers} \\ \text{get different answer lists} \end{gathered}

    why it is allowed: Pretend two different orders of the same numbers gave the same answers. By line 1 they get the same moves, carrying what stands at each place to the same place on both. So they end different, at most one in order: a swap puts 2, 1 in order but not 1, 2. Yet the sort puts every row in order, so each order gets its own list.

  3. the move: fill out short lists

    the line:
    with W the most comparisonson any order, every order getsa list of exactly W answers\begin{gathered} \text{with } W \text{ the most comparisons} \\ \text{on any order, every order gets} \\ \text{a list of exactly } W \text{ answers} \end{gathered}
    3 2 13 1 22 1 32 3 11 3 21 2 3yesnoa yes added
    Short lists carried down to 3 answers by dotted yeses. No no, for 1, 2, 3, begins no other list, so no no yes is new.

    why it is allowed: Let WW be the most comparisons on any order. Fill each shorter list out to WW answers with pretend yeses, so all have the one length line 4 counts. Filling adds only at the end. And no list begins another: if one did, by line 1 its row and the longer one's would stop together, so the longer would not go on. So the filled lists stay different.

  4. the move: count both

    the line:
    2W is at least n!\begin{gathered} 2^W \text{ is at least } n! \end{gathered}
    nnordersthe floorits lists
    3638
    424532
    51207128
    840,3201665,536
    12479,001,60029536,870,912
    One answer fewer gives half the lists, too few.

    why it is allowed: Each answer doubles the lists, so WW answers make 2W2^W, against n!n! orders. By lines 2 and 3, lists are at least as many as orders. For 4, the 16 lists of 4 answers are too few for 24.

  5. the move: name the floor

    the line:
    F=the fewest doublingsof 1 that reach n!\begin{gathered} F = \text{the fewest doublings} \\ \text{of 1 that reach } n! \end{gathered}

    why it is allowed: Let FF be the fewest doublings of 1 that reach n!n! or pass it. For 4, four doublings reach only 16, short of 24, and the fifth, 32, passes it.

  6. the move: at least FF

    the line:
    W is at least F\begin{gathered} W \text{ is at least } F \end{gathered}

    why it is allowed: By line 4, WW doublings of 1 reach n!n!, and by line 5 no fewer than FF do. So WW is at least FF.

  7. the move: halving and logarithms

    the line:
    F=⌈log⁡2 n!⌉F = \lceil \log_2\, n! \rceil
    where does this come from?
    question 4 of the page halving and logarithmsHalve nn, rounding up each time. How many halvings reach 1?
    1. the move: name the log rounded up

      the line:
      C=⌈log⁡2 n⌉C = \lceil \log_2\, n \rceil

      why it is allowed: Here nn is the number halved, from 2 up. For 11, CC is 4.

    2. the move: rounding up never takes off

      the line:
      log⁡2 n≤⌈log⁡2 n⌉\log_2\, n \le \lceil \log_2\, n \rceil

      why it is allowed: The bracket is CC. For 11, 3.46 is at most 4.

    3. the move: rounding up adds less than 1

      the line:
      ⌈log⁡2 n⌉−1<log⁡2 n\lceil \log_2\, n \rceil - 1 < \log_2\, n

      why it is allowed: For 11, 3 is below 3.46.

    4. the move: raise 2 to each side of line 2

      the line:
      2log⁡2 n≤2⌈log⁡2 n⌉2^{\log_2\, n} \le 2^{\lceil \log_2\, n \rceil}

      why it is allowed: As in line 4 of question 2 of the page halving and logarithms.

    5. the move: 2 to the log of n is n

      the line:
      n≤2⌈log⁡2 n⌉n \le 2^{\lceil \log_2\, n \rceil}

      why it is allowed: As in line 5 of question 2 of the page halving and logarithms. For 11, 11 is at most 16.

    6. the move: raise 2 to each side of line 3

      the line:
      2⌈log⁡2 n⌉−1<2log⁡2 n2^{\lceil \log_2\, n \rceil - 1} < 2^{\log_2\, n}

      why it is allowed: As in line 4.

    7. the move: 2 to the log of n is n

      the line:
      2⌈log⁡2 n⌉−1<n2^{\lceil \log_2\, n \rceil - 1} < n

      why it is allowed: As in line 5. For 11, 8 is below 11.

    8. the move: halve both sides of line 5

      the line:
      n/2≤2⌈log⁡2 n⌉/2n / 2 \le 2^{\lceil \log_2\, n \rceil} / 2

      why it is allowed: Halving both sides keeps it true.

    9. the move: write the half as a power

      the line:
      n/2≤2⌈log⁡2 n⌉−1n / 2 \le 2^{\lceil \log_2\, n \rceil - 1}

      why it is allowed: As in line 9 of question 2 of the page halving and logarithms. For 11, 5.5 is at most 8.

    10. the move: round the half up

      the line:
      ⌈n/2⌉≤2⌈log⁡2 n⌉−1\lceil n / 2 \rceil \le 2^{\lceil \log_2\, n \rceil - 1}

      why it is allowed: ⌈n/2⌉\lceil n / 2 \rceil is the half rounded up: the smallest whole number at or above it, 6 for 11. The right side, 8 for 11, is whole, as CC is at least 1. By line 9 it is at or above the half, so no smaller than the half rounded up.

    11. the move: halve both sides of line 7

      the line:
      2⌈log⁡2 n⌉−1/2<n/22^{\lceil \log_2\, n \rceil - 1} / 2 < n / 2

      why it is allowed: Halving both sides keeps it true.

    12. the move: write the half as a power

      the line:
      2⌈log⁡2 n⌉−2<n/22^{\lceil \log_2\, n \rceil - 2} < n / 2
      numberlog× 2+ 11/2−1102142
      One half, a step left of 1, is 2 to the power minus 1.

      why it is allowed: As in line 9 of question 2 of the page halving and logarithms. For 11, 4 is below 5.5. For 2, CC is 1, so this is 2 to the power minus 1, one half, as drawn.

    13. the move: round the half up

      the line:
      2⌈log⁡2 n⌉−2<⌈n/2⌉2^{\lceil \log_2\, n \rceil - 2} < \lceil n / 2 \rceil

      why it is allowed: Rounding up never takes off. For 11, 4 is below 6.

    14. the move: take the log of line 10

      the line:
      log⁡2 ⌈n/2⌉≤log⁡2 2⌈log⁡2 n⌉−1\log_2\, \lceil n / 2 \rceil \le \log_2\, 2^{\lceil \log_2\, n \rceil - 1}

      why it is allowed: As in line 14 of question 2 of the page halving and logarithms.

    15. the move: the log of a power of 2 is the power

      the line:
      log⁡2 ⌈n/2⌉≤⌈log⁡2 n⌉−1\log_2\, \lceil n / 2 \rceil \le \lceil \log_2\, n \rceil - 1

      why it is allowed: For 11, the log of 6, about 2.58, is at most 3.

    16. the move: take the log of line 13

      the line:
      log⁡2 2⌈log⁡2 n⌉−2<log⁡2 ⌈n/2⌉\log_2\, 2^{\lceil \log_2\, n \rceil - 2} < \log_2\, \lceil n / 2 \rceil

      why it is allowed: As in line 14. For 2, the log of one half is minus 1, below the log of 1, which is 0.

    17. the move: the log of a power of 2 is the power

      the line:
      ⌈log⁡2 n⌉−2<log⁡2 ⌈n/2⌉\lceil \log_2\, n \rceil - 2 < \log_2\, \lceil n / 2 \rceil

      why it is allowed: For 11, 2 is below about 2.58.

    18. the move: round the log up

      the line:
      ⌈log⁡2 ⌈n/2⌉⌉=⌈log⁡2 n⌉−1\lceil \log_2\, \lceil n / 2 \rceil \rceil = \lceil \log_2\, n \rceil - 1
      the numberaboveat mostits log rounded up
      118164
      6483
      3242
      2121
      11/210
      Each halving takes 1 off the log rounded up.

      why it is allowed: By lines 15 and 17, the log of the half is above two less than CC and at most one less, so it rounds up to one less. For 11, about 2.58 rounds up to 3.

    19. the move: use line 18 again and again

      the line:
      after C halvings,rounding up, the logrounded up is 0\begin{gathered} \text{after } C \text{ halvings,} \\ \text{rounding up, the log} \\ \text{rounded up is 0} \end{gathered}

      why it is allowed: While the log rounded up is 1 or more, the log is above 0, so the number is above 1: at least 2. So line 18 takes 1 off each halving, and the number stays 2 or more until exactly CC halvings. For 11, 4, 3, 2, 1, 0.

    20. the move: a log rounded up to 0 belongs to 1

      the line:
      C halvings, rounding up,bring n to 1\begin{gathered} C \text{ halvings, rounding up,} \\ \text{bring } n \text{ to 1} \end{gathered}

      why it is allowed: Such a log is at most 0, so its number is at most 1, and so is 1.

    21. the move: read lines 5 and 7 as doublings

      the line:
      C doublings of 1 reach n,one fewer do not\begin{gathered} C \text{ doublings of 1 reach } n, \\ \text{one fewer do not} \end{gathered}

      why it is allowed: Doubling 1 gives the powers of 2. By line 5, CC doublings get to or past nn; by line 7, one fewer stay below. For 11, 8 stays below and 16 gets past.

    22. the move: count merge sort's rounds

      the line:
      merge sort on this sitemakes C rounds\begin{gathered} \text{merge sort on this site} \\ \text{makes } C \text{ rounds} \end{gathered}
      the row: 5, 9, 2, 7, 11, 1, 8, 3, 10, 6, 411111111111start222221round 1443round 283round 311round 42a run, its length insideno partner, carried downthe first runall in one runa merge in round 2, its numbers59272579goes straight in, the other run used up
      Round 2 merges 5, 9 and 2, 7 into 2, 5, 7, 9.
      after roundruns
      start11
      16
      23
      32
      41
      The first run holds 1, 2, 4, 8, then all 11: four rounds. The count of runs is 11 halved, rounding up.

      why it is allowed: Merge sort starts from runs of 1, whatever the row. Each round merges neighbouring runs in pairs, so the first run doubles, the last round taking only what is left. By line 21 it holds all nn after CC rounds, not fewer.

    23. the move: read it

      the line:
      C halvings,rounding up, andC rounds of merge sort\begin{gathered} C \text{ halvings,} \\ \text{rounding up, and} \\ C \text{ rounds of merge sort} \end{gathered}

      why it is allowed: By lines 20 and 22, one count gives both the halvings and merge sort's rounds. For 11, four of each.

    the whole page: halving and logarithms

    why it is allowed: The fewest doublings of 1 reaching a number from 2 up are its log to base 2 rounded up: 5 for 24. The box under this line, from the page halving and logarithms, shows it at its lines 5 and 7.

  8. the move: read it

    the line:
    no comparing sort makes feweron its worst row\begin{gathered} \text{no comparing sort makes fewer} \\ \text{on its worst row} \end{gathered}

    why it is allowed: By lines 6 and 7, every comparing sort that makes no random choices makes at least ⌈log⁡2 n!⌉\lceil \log_2\, n! \rceil comparisons on its worst row of nn. It is only a floor: for 12 numbers it is 29, yet the best sort for 12 needs 30 on its worst row. An outside result, and no line here rests on it (Mark Wells, 1965; Knuth, The Art of Computer Programming, volume 3, section 5.3.1).

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

question 4How does log⁡2 n!\log_2\, n! grow?
  1. the move: name the log

    the line:
    G=log⁡2 n!G = \log_2\, n!

    why it is allowed: Let GG be the log to base 2 of n!n!, for nn from 4 as lines 12 and 15 need. For 8, about 15.30.

  2. the move: factors at most n

    the line:
    n!≤nnn! \le n^n

    why it is allowed: n!n! multiplies nn whole numbers, each at most nn. Putting nn for each gives nnn^n, read nn to the power nn, no smaller. For 8, 40,320 against 16,777,216.

  3. the move: bigger number, bigger log

    the line:
    log⁡2 n!≤log⁡2 nn\log_2\, n! \le \log_2\, n^n

    why it is allowed: On a number line of powers of 2, 16 stands right of 8, and its log, 4, right of 8's log, 3. Any two numbers go the same way, as the page halving and logarithms shows, so line 2 holds for the logs.

  4. the move: into line 1

    the line:
    G≤log⁡2 nnG \le \log_2\, n^n

    why it is allowed: By line 3, as GG is the log of n!n!.

  5. the move: log of a power

    the line:
    G≤n log⁡2 nG \le n \,\log_2\, n

    why it is allowed: For 8: 8 is three 2s, so 8 to the power 8 is 24 2s, since multiplying powers of 2 adds the powers. Each number is 2 raised to its log, so the log of a product adds the logs. nnn^n is a product of nn factors, each nn, so its log is nn times log⁡2 n\log_2\, n.

  6. the move: keep the top half

    the line:
    n!≥the product ofits ⌈n/2⌉ factorsabove half of n\begin{gathered} n! \ge \text{the product of} \\ \text{its } \lceil n/2 \rceil \text{ factors} \\ \text{above half of } n \end{gathered}

    why it is allowed: Drop the factors 1 to half of nn rounded down; each is at least 1, so the product gets no bigger. Half of nn rounded down and rounded up add up to nn, as 3 and 4 for 7. So ⌈n/2⌉\lceil n/2 \rceil are kept, read half of nn rounded up.

  7. the move: half of n for each

    the line:
    n!≥(n2)⌈n/2⌉n! \ge \left(\frac{n}{2}\right)^{\lceil n/2 \rceil}
    for 8multiplied
    8 down to 140,320
    8 × 7 × 6 × 51,680
    4 × 4 × 4 × 4256
    Drop 4 down to 1, then put 4, half of 8, for each factor kept.

    why it is allowed: Each kept factor is above half of nn, so putting half of nn for each gives no bigger product.

  8. the move: bigger number, bigger log

    the line:
    log⁡2 n!≥log⁡2(n2)⌈n/2⌉\log_2\, n! \ge \log_2 \left(\frac{n}{2}\right)^{\lceil n/2 \rceil}

    why it is allowed: As in line 3.

  9. the move: into line 1

    the line:
    G≥log⁡2(n2)⌈n/2⌉G \ge \log_2 \left(\frac{n}{2}\right)^{\lceil n/2 \rceil}

    why it is allowed: By line 8, as GG is the log of n!n!.

  10. the move: log of a power

    the line:
    G≥⌈n2⌉log⁡2 n2G \ge \left\lceil \frac{n}{2} \right\rceil \log_2\, \frac{n}{2}

    why it is allowed: As in line 5. For 8, 4 times 2.

  11. the move: rounding up

    the line:
    ⌈n2⌉≥n2\left\lceil \frac{n}{2} \right\rceil \ge \frac{n}{2}

    why it is allowed: Rounding up makes no smaller, as 3.5 goes up to 4.

  12. the move: log of half of n

    the line:
    log⁡2 n2≥1\log_2\, \frac{n}{2} \ge 1

    why it is allowed: From 4 on, half of nn is at least 2, whose log is 1; by line 3, bigger numbers have bigger logs.

  13. the move: drop the rounding

    the line:
    G≥n2 log⁡2 n2G \ge \frac{n}{2} \,\log_2\, \frac{n}{2}

    why it is allowed: By line 11, half of nn is at most ⌈n/2⌉\lceil n/2 \rceil, as 3.5 against 4 for 7. Each multiplies the log of half of nn, above zero by line 12, so putting half of nn in line 10 makes it no bigger.

  14. the move: halving takes 1 off

    the line:
    G≥n2(log⁡2 n−1)G \ge \frac{n}{2} \left(\log_2\, n - 1\right)

    why it is allowed: nn is 2 times half of nn, and the log of 2 is 1. So by line 5 the log of half of nn is log⁡2 n−1\log_2\, n - 1. For 8, the log of 4 is 3 less 1.

  15. the move: a fact about n

    the line:
    log⁡2 n2≤log⁡2 n−1\frac{\log_2\, n}{2} \le \log_2\, n - 1

    why it is allowed: From 4 on, log⁡2 n\log_2\, n is at least 2, so half of it is at least 1, and taking 1 away leaves at least half. For 8, 1.5 against 2.

  16. the move: the smaller part

    the line:
    G≥n2×log⁡2 n2G \ge \frac{n}{2} \times \frac{\log_2\, n}{2}

    why it is allowed: By line 15, putting half of log⁡2 n\log_2\, n for log⁡2 n−1\log_2\, n - 1 in line 14 makes it no bigger, as in line 13. For 8, 4 times 1.5, 6.

  17. the move: multiply out

    the line:
    G≥n log⁡2 n4G \ge \frac{n \,\log_2\, n}{4}
    the lognumbers0102030400246810the lognumbers0102030400246810
    • n log⁡2 nn \,\log_2\, n
    • the log of n!n!
    • a quarter of n log⁡2 nn \,\log_2\, n
    The log of n!n! between the other two, from 1 to 10 numbers. At 8: 24, about 15.30, and 6.

    why it is allowed: Half of nn times half of log⁡2 n\log_2\, n.

  18. the move: a ceiling

    the line:
    G∈O(n log⁡2 n)G \in O(n \,\log_2\, n)

    why it is allowed: G∈O(n log⁡2 n)G \in O(n \,\log_2\, n), read GG is in big O of n log⁡2 nn \,\log_2\, n, says a fixed multiple of it is a ceiling of GG. By line 5, 1 times it, from 4 on.

  19. the move: a floor

    the line:
    G∈Ω(n log⁡2 n)G \in \Omega(n \,\log_2\, n)

    why it is allowed: G∈Ω(n log⁡2 n)G \in \Omega(n \,\log_2\, n), read big omega, says a fixed multiple, above zero, is a floor of GG, a floor on growth, not the sorting floor. By line 17, a quarter, from 4 on.

  20. the move: both

    the line:
    G∈Θ(n log⁡2 n)G \in \Theta(n \,\log_2\, n)

    why it is allowed: G∈Θ(n log⁡2 n)G \in \Theta(n \,\log_2\, n), read big theta, says both, by lines 18 and 19. GG grows like n log⁡2 nn \,\log_2\, n.

try it with a small nn: at n=8n = 8, line 1 gives GG, about 15.3

question 5How does the floor grow, and what does that say of every worst row?
  1. the move: name the floor

    the line:
    F=⌈log⁡2 n!⌉F = \lceil \log_2\, n! \rceil

    why it is allowed: Let FF be the floor of question 3, for nn from 4 as line 3 needs. For 8, 16.

  2. the move: rounding up

    the line:
    F≥log⁡2 n!F \ge \log_2\, n!

    why it is allowed: Rounding up makes no smaller. For 8, 16 against about 15.30.

  3. the move: question 4's floor

    the line:
    F≥n log⁡2 n4F \ge \frac{n \,\log_2\, n}{4}

    why it is allowed: By line 17 of question 4. For 8, 6.

  4. the move: adds less than 1

    the line:
    F≤log⁡2 n!+1F \le \log_2\, n! + 1

    why it is allowed: Rounding up adds less than 1. For 8, about 16.30.

  5. the move: question 4's ceiling

    the line:
    F≤n log⁡2 n+1F \le n \,\log_2\, n + 1

    why it is allowed: By line 5 of question 4. For 8, 25.

  6. the move: a fact about n

    the line:
    1≤n log⁡2 n1 \le n \,\log_2\, n

    why it is allowed: From 4 on, log⁡2 n\log_2\, n is at least 2, so n log⁡2 nn \,\log_2\, n is at least 8.

  7. the move: put it for the 1

    the line:
    F≤n log⁡2 n+n log⁡2 nF \le n \,\log_2\, n + n \,\log_2\, n

    why it is allowed: By line 6, this makes the right side of line 5 no smaller.

  8. the move: add them

    the line:
    F≤2n log⁡2 nF \le 2 n \,\log_2\, n

    why it is allowed: For 8, 48.

  9. the move: a ceiling

    the line:
    F∈O(n log⁡2 n)F \in O(n \,\log_2\, n)

    why it is allowed: By line 8, as in line 18 of question 4, the multiple 2.

  10. the move: a floor

    the line:
    F∈Ω(n log⁡2 n)F \in \Omega(n \,\log_2\, n)

    why it is allowed: By line 3, as in line 19 of question 4, the multiple a quarter.

  11. the move: both

    the line:
    F∈Θ(n log⁡2 n)F \in \Theta(n \,\log_2\, n)

    why it is allowed: By lines 9 and 10. By lines 3 and 8, from 4 on, FF lies between a quarter of n log⁡2 nn \,\log_2\, n and twice it.

  12. the move: the worst row

    the line:
    W is at least F\begin{gathered} W \text{ is at least } F \end{gathered}
    nnthe floormerge sortbubble sort
    4556
    57910
    6101115
    7131421
    Two of this site's sorts, their most comparisons over every order of nn. Neither is below the floor.

    why it is allowed: WW is the most comparisons a comparing sort with no random choices makes on any order of nn, at least FF by lines 6 and 7 of question 3.

  13. the move: put line 3 in

    the line:
    W is at least a quarterof n log⁡2 n, from 4 on\begin{gathered} W \text{ is at least a quarter} \\ \text{of } n \,\log_2\, n \text{, from 4 on} \end{gathered}

    why it is allowed: By lines 3 and 12. For 8, 16 against 6.

  14. the move: every worst row

    the line:
    W grows at least as fastas a quarter of n log⁡2 n\begin{gathered} W \text{ grows at least as fast} \\ \text{as a quarter of } n \,\log_2\, n \end{gathered}

    why it is allowed: Line 13 holds for every comparing sort with no random choices, so n log⁡2 nn \,\log_2\, n is a floor on the growth of every such worst row.

try it with a small nn: at n=8n = 8, line 1 gives F=16F = 16, which you can work out by hand

a worked example

Find the floor for 6 numbers.

  1. By question 1, 6 numbers stand in 6 × 5 × 4 × 3 × 2 × 1 orders, 720.
  2. By question 2, 9 answers make 512 lists, too few, and 10 make 1,024.
  3. By question 3, a comparing sort with no random choices takes, on its worst row of 6, at least 10 comparisons: the log of 720, about 9.49, rounded up.

the trap

check yourself

  1. In how many orders can 5 different numbers stand?

    the answer

    By question 1, 5 times 4 times 3 times 2 times 1, which is 120.

  2. At least how many comparisons does a comparing sort with no random choices make on its worst row of 5?

    the answer

    By question 3, 7. 6 give 64 lists, too few for 120 orders, and 7 give 128.

  3. Can a comparing sort with no random choices put every row of 8 in order in at most 15 comparisons?

    the answer

    No. 15 give 32,768 lists, too few for 40,320 orders, so by question 3 its worst row takes at least 16.