You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sorting/Radix Sort/README.md
+32-14Lines changed: 32 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,12 +34,12 @@ After implementing Radix Sort algorithm...
34
34
## 📊 Flowchart
35
35
```
36
36
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
43
43
```
44
44
45
45
## 🧮 Algorithm
@@ -55,28 +55,46 @@ The Input array is given as,
55
55
```
56
56
[170, 45, 75, 90, 802, 24, 2, 66]
57
57
```
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,
0 commit comments