Skip to content

Commit 86825a6

Browse files
committed
docs: updated readme to talk about number systems
1 parent 6d8381b commit 86825a6

File tree

1 file changed

+14
-9
lines changed
  • src/main/java/algorithms/sorting/radixSort

1 file changed

+14
-9
lines changed

src/main/java/algorithms/sorting/radixSort/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@ This takes advantage of the concept of place value.
1717

1818
## Complexity Analysis
1919
**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:
2225

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))
2629

27-
**Space**: O(n + 10)
30+
**Space**: O(n + k)
2831

2932
## Notes
3033
- Radix sort's time complexity is dependent on the maximum number of digits in each element,
3134
hence it is ideal to use it on integers with a large range and with little digits.
3235
- This could mean that Radix Sort might end up performing worst on small sets of data
3336
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.
3539

3640
### Common Misconception
3741
- 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.
3943
- 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

Comments
 (0)