|
3 | 3 | _Read this in other languages:_
|
4 | 4 | [_Português_](README.pt-BR.md),
|
5 | 5 |
|
6 |
| -In computer science, **radix sort** is a non-comparative integer sorting |
7 |
| -algorithm that sorts data with integer keys by grouping keys by the individual |
| 6 | +In computer science, **radix sort** is a non-comparative integer sorting |
| 7 | +algorithm that sorts data with integer keys by grouping keys by the individual |
8 | 8 | digits which share the same significant position and value. A positional notation
|
9 |
| -is required, but because integers can represent strings of characters |
10 |
| -(e.g., names or dates) and specially formatted floating point numbers, radix |
| 9 | +is required, but because integers can represent strings of characters |
| 10 | +(e.g., names or dates) and specially formatted floating point numbers, radix |
11 | 11 | sort is not limited to integers.
|
12 | 12 |
|
13 | 13 | *Where does the name come from?*
|
14 | 14 |
|
15 | 15 | In mathematical numeral systems, the *radix* or base is the number of unique digits,
|
16 |
| -including the digit zero, used to represent numbers in a positional numeral system. |
17 |
| -For example, a binary system (using numbers 0 and 1) has a radix of 2 and a decimal |
| 16 | +including the digit zero, used to represent numbers in a positional numeral system. |
| 17 | +For example, a binary system (using numbers 0 and 1) has a radix of 2 and a decimal |
18 | 18 | system (using numbers 0 to 9) has a radix of 10.
|
19 | 19 |
|
20 | 20 | ## Efficiency
|
21 | 21 |
|
22 |
| -The topic of the efficiency of radix sort compared to other sorting algorithms is |
23 |
| -somewhat tricky and subject to quite a lot of misunderstandings. Whether radix |
24 |
| -sort is equally efficient, less efficient or more efficient than the best |
25 |
| -comparison-based algorithms depends on the details of the assumptions made. |
26 |
| -Radix sort complexity is `O(wn)` for `n` keys which are integers of word size `w`. |
27 |
| -Sometimes `w` is presented as a constant, which would make radix sort better |
28 |
| -(for sufficiently large `n`) than the best comparison-based sorting algorithms, |
29 |
| -which all perform `O(n log n)` comparisons to sort `n` keys. However, in |
30 |
| -general `w` cannot be considered a constant: if all `n` keys are distinct, |
31 |
| -then `w` has to be at least `log n` for a random-access machine to be able to |
32 |
| -store them in memory, which gives at best a time complexity `O(n log n)`. That |
33 |
| -would seem to make radix sort at most equally efficient as the best |
| 22 | +The topic of the efficiency of radix sort compared to other sorting algorithms is |
| 23 | +somewhat tricky and subject to quite a lot of misunderstandings. Whether radix |
| 24 | +sort is equally efficient, less efficient or more efficient than the best |
| 25 | +comparison-based algorithms depends on the details of the assumptions made. |
| 26 | +Radix sort complexity is `O(wn)` for `n` keys which are integers of word size `w`. |
| 27 | +Sometimes `w` is presented as a constant, which would make radix sort better |
| 28 | +(for sufficiently large `n`) than the best comparison-based sorting algorithms, |
| 29 | +which all perform `O(n log n)` comparisons to sort `n` keys. However, in |
| 30 | +general `w` cannot be considered a constant: if all `n` keys are distinct, |
| 31 | +then `w` has to be at least `log n` for a random-access machine to be able to |
| 32 | +store them in memory, which gives at best a time complexity `O(n log n)`. That |
| 33 | +would seem to make radix sort at most equally efficient as the best |
34 | 34 | comparison-based sorts (and worse if keys are much longer than `log n`).
|
35 | 35 |
|
36 |
| - |
| 36 | + |
37 | 37 |
|
38 | 38 | ## Complexity
|
39 | 39 |
|
|
0 commit comments