Skip to content

Commit 99cf2fb

Browse files
authored
Update README.md
1 parent 845767a commit 99cf2fb

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

Sorting/Radix Sort/README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ After implementing Radix Sort algorithm...
3434
## 📊 Flowchart
3535
```
3636
radixSort(arr)
37-
max = largest element in the given array
38-
d = number of digits in the largest element (or, max)
39-
Now, create d buckets of size 0 - 9
40-
for i -> 0 to d
41-
sort the array elements using counting sort (or any stable sort) according to the digits at
42-
the ith place
37+
max = largest element in the given array
38+
d = number of digits in the largest element (or, max)
39+
Now, create d buckets of size 0 - 9
40+
for i -> 0 to d
41+
sort the array elements using counting sort (or any stable sort) according to the digits at
42+
the ith place
4343
```
4444

4545
## 🧮 Algorithm
@@ -55,28 +55,46 @@ The Input array is given as,
5555
```
5656
[170, 45, 75, 90, 802, 24, 2, 66]
5757
```
58+
In the given array, the largest element is `802` that have `3` digits in it. So, the loop will run up to three times (i.e., to the hundreds place). That means three passes are required to sort the array.
59+
60+
Now, first sort the elements on the basis of unit place digits (i.e., `x = 0`). Here, we are using the counting sort algorithm to sort the elements.
61+
62+
- **Pass 1**: In the first pass, the list is sorted on the basis of the digits at 0's place.
63+
```
64+
[170, 90, 802, 2, 24, 45, 75, 66]
65+
```
66+
- **Pass 2**: In this pass, the list is sorted on the basis of the next significant digits (i.e., digits at 10th place).
67+
```
68+
[2, 802, 24, 45, 66, 75, 170, 90]
69+
```
70+
- **Pass 3**: In this pass, the list is sorted on the basis of the next significant digits (i.e., digits at 100th place).
71+
```
72+
[2, 24, 45, 66, 75, 90, 170, 802]
73+
```
74+
Now, the array is sorted in ascending order. The final result is,
75+
```
76+
[2, 24, 45, 66, 75, 90, 170, 802]
77+
```
5878

5979
## 💻 Input and Output
6080
- **Test Case 1 :**
6181
```
6282
Input Given :
63-
s = [1 , 3 , 0 , 5 , 8 , 5]
64-
f = [2 , 4 , 6 , 7 , 9 , 9]
83+
arr = [170, 45, 75, 90, 802, 24, 2, 66]
6584
```
6685

67-
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Greedy/Activity%20Selection%20Problem/Images/asp-1.png)
86+
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Sorting/Radix%20Sort/Images/radix-sort-2.png)
6887

6988
- **Test Case 2 :**
7089
```
7190
Input Given :
72-
s = [1, 2, 3, 4, 7, 8, 9, 9, 11, 12]
73-
f = [3, 5, 4, 7, 10, 9, 11, 13, 12, 14]
91+
arr = [181, 289, 390, 121, 145, 736, 514, 888, 122]
7492
```
75-
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Greedy/Activity%20Selection%20Problem/Images/asp-2.png)
93+
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Sorting/Radix%20Sort/Images/radix-sort-1.png)
7694

7795
## ⏰ Time and Space complexity
78-
- **Time Complexity :** `O(n)`.
79-
- **Space Complexity :** `O(1)`.
96+
- **Time Complexity :** `O(n+k)`.
97+
- **Space Complexity :** `O(n+k)`.
8098

8199
---------------------------------------------------------------
82100
## 🖋️ Author

0 commit comments

Comments
 (0)