BWith at most three digits, it makes at most placings.
DIt compares no two numbers.
pen and paper
5question 5about 10 minutes
Radix sort works on 520, 37, 804, 61.
Write the row after each pass.
Count the placings, and check against .
In the hundreds pass, 37 and 61 share the digit 0. Why does 37 stay first?
a hint
Read 37 as 037 and 61 as 061.
a worked answer
After the ones pass: 520, 61, 804, 37. After the tens pass: 804, 520, 37, 61. After the hundreds pass: 37, 61, 520, 804. Three passes of 4 placings make 12, and 3 times 4 is 12. In the hundreds pass the total for digit 0 is 2. From the back, 61 is sent first, to place 2, then 37 to place 1, so 37 stays before 61.
Why does radix sort make exactly placings when the biggest has three digits?9 of 9 shown
1the move: price one pass
the line:
The ones pass on 305, 7, 42, 618. From the back, 618 goes to place 4, 42 to place 1, 7 to place 3 and 305 to place 2. Four placings.
why it is allowed: From the last number back to the first, each number is sent to its place once. The picture is the ones pass on 305, 7, 42, 618.
2the move: count the passes
the line:
after
the row
the start
305, 7, 42, 618
the ones pass
42, 305, 7, 618
the tens pass
305, 7, 618, 42
the hundreds pass
7, 42, 305, 618
305, 7, 42, 618 after each of its three passes. Each pass sends all four numbers.
why it is allowed: One pass for each digit of the biggest number, ones, tens and hundreds. The biggest, 618, has three digits.
guess it, then
3the move: add the passes
the line:
why it is allowed: is the placings made. By lines 1 and 2, placings in each of 3 passes.
guess it, then
4the move: gather
the line:
why it is allowed: By line 3, three lots of . For 305, 7, 42, 618, that is 12.
guess it, then
5the move: a ceiling
the line:
why it is allowed: By line 4, is , so it is at most .
guess it, then
6the move: read it as a bound
the line:
why it is allowed: By line 5, is at most 3 times .
guess it, then
7the move: a floor
the line:
why it is allowed: By line 4, is at least too.
guess it, then
8the move: read it as a bound
the line:
why it is allowed: By line 7, never drops below 3 times .
guess it, then
9the move: ceiling and floor together
the line:
why it is allowed: Lines 6 and 8 bound by the same growth, .
guess it, then
try it with a small : at , line 3 gives , which you can work out by hand
Say you sort 1,000 different whole numbers from 0 up.
Why is the biggest at least 999?
At least how many passes, and how many placings?
And for 10,000 different numbers?
a hint
Count the whole numbers from 0 to 998.
a worked answer
Only 999 whole numbers lie from 0 to 998, so 1,000 different ones reach 999 or more. That is at least three digits: at least 3 passes and 3,000 placings, exactly that for the numbers 0 to 999. 10,000 different numbers need at least four digits, at least 40,000 placings. Numbered from 0, ten times the numbers take more than ten times the placings.