Skip to content

Commit 5e79193

Browse files
committed
SRS background
1 parent 57e7c78 commit 5e79193

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/algorithms/explanations/MSDRadixSortExp.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ mask bit of each key:
4141
* Increment ```i``` until an element with a 1 as the mask bit is reached
4242
* Decrement ```j``` until an element with a 0 as the mask bit is reached
4343

44-
* If the two guards have not crossed, perform a swap to ensure that 0s are placed on the left and 1s on the right.
44+
* If the two indices have not met/crossed, perform a swap to ensure that 0s are placed on the left and 1s on the right.
4545

4646
## Complexity
4747
### Time Complexity
48-
* Partitioning takes```O(n)```, where ```n``` is the number elements in the
48+
* Partitioning takes ```O(n)```, where ```n``` is the number elements in the
4949
array.
50-
* If we *assume the number of bits is limited* the overall time complexity is: ```O(n)```
50+
* If we *assume the maximum number of digits is fixed* the overall time complexity is: ```O(n)```
5151
* Note that the best comparison-based sorting algorithms have ```O(n log n)```
5252
complexity, but the number of bits is typically related to ```log n```
53+
(otherwise there must be many duplicate keys)
5354
so radix sorts are not necessarily better.
5455

5556
### Space Complexity

src/algorithms/explanations/StraightRadixSortExp.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## Introduction
66
Unlike most sorting algorithms, which are based on *comparison* of whole
77
keys, radix sorting is based on examining individual "digits" in the
8-
keys. For integers (used here) this could be decimal digits (base 10), bits (base 2) or and other
8+
keys. For integers (used here) this could be decimal digits (base 10), bits (base 2) or any other
99
base. Using bytes (base 256) has efficiency advantages but here we use base 4
1010
(digits 0-3) for illustration.
1111
Straight Radix Sort (also known as Least Significant Digit Radix Sort)
@@ -23,13 +23,17 @@ The ```Radixsort``` function begins by determining the maximum number of digits,
2323
in the data. This number defines how many iterations the algorithm will go through,
2424
starting from the least significant (right-most) digit moving toward the most
2525
significant (left-most). Here we use base 4 digits (0-3 or two bits)
26-
and show values in binary.
26+
and show values in decimal, base 4 (the most helpful in understanding
27+
the algorithm) and binary.
2728

2829
### 2. Outer Loop
2930
For each digit (scanning right to left), *Counting Sort* is performed on that
3031
digit. This leave the array sorted.
3132

3233
### 3. Counting Sort
34+
35+
Counting sort has four parts:
36+
3337
* Counting occurrences of each digit (00, 01, 10 and 11 in binary)
3438
* For each key in the array, the digit at the current position is extracted.
3539
* The algorithm counts how many times each digit occurs.
@@ -47,10 +51,11 @@ the keys sorted on the current digit, is copied back to the original array ```A`
4751

4852
## Complexity
4953
### Time Complexity
50-
* Each iteration uses ```Countingsort```, which requires ```O(n)```, where n is the number of elements.
51-
* If we *assume the number of digits is limited* the overall time complexity is: ```O(n)```
54+
* Each iteration uses ```Countingsort```, which takes ```O(n)``` time, where n is the number of elements.
55+
* If we *assume the maximum number of digits is fixed* the overall time complexity is: ```O(n)```
5256
* Note that the best comparison-based sorting algorithms have ```O(n log n)```
5357
complexity, but the number of digits is typically related to ```log n```
58+
(otherwise there must be many duplicate keys)
5459
so radix sorts are not necessarily better.
5560

5661
### Space Complexity

0 commit comments

Comments
 (0)