@@ -17,24 +17,29 @@ This takes advantage of the concept of place value.
17
17
18
18
## Complexity Analysis
19
19
** Time** :
20
- Note that we will always need to iterate through 10 different queues to rebuild our original array,
21
- and we iterate through all * w* positions, this results in:
20
+ Let * k* be the base of the number system being used. For integers in java, it is base 10
21
+ (we have digits 0 to 9), in the case of base 2 (binary), we only have 2 digits (1, 0),
22
+ base 3, (0, 1, 2). Hence, we can see that the base of the number system determines the number of
23
+ different queues we need to iterate through to rebuild our original array, additionally, we also
24
+ need to iterate through all * w* positions (digits), this results in the following complexities:
22
25
23
- - Worst case: O(w * (n + 10 ))
24
- - Average case: O(w * (n + 10 ))
25
- - Best case (sorted array): O(w * (n + 10 ))
26
+ - Worst case: O(w * (n + k ))
27
+ - Average case: O(w * (n + k ))
28
+ - Best case (sorted array): O(w * (n + k ))
26
29
27
- ** Space** : O(n + 10 )
30
+ ** Space** : O(n + k )
28
31
29
32
## Notes
30
33
- Radix sort's time complexity is dependent on the maximum number of digits in each element,
31
34
hence it is ideal to use it on integers with a large range and with little digits.
32
35
- This could mean that Radix Sort might end up performing worst on small sets of data
33
36
if any one given element has a in-proportionate amount of digits.
34
- - Counting sort is used as a sub-routine within the Radix Sort process.
37
+ - It is interesting to note that counting sort is used as a sub-routine within the
38
+ Radix Sort process.
35
39
36
40
### Common Misconception
37
41
- While not immediately obvious, we can see that radix sort is a stable sorting algorithm as
38
- they are enqueued in a manner where the first observed element will be at the head of the queue.
42
+ they are enqueued in a manner where the first observed element remains at the head of the queue.
39
43
- While it is non-comparison based, not that total ordering of elements is still required -
40
- except now this property is forced upon the algorithm in the manner of the queues.
44
+ except now this property is forced upon the algorithm in the manner of how the queues
45
+ are structured.
0 commit comments