Skip to content

Commit 845767a

Browse files
authored
Create README.md
1 parent 5e4309c commit 845767a

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

Sorting/Radix Sort/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Radix Sort Algorithm
2+
🔴 Language used : **Python 3**
3+
4+
## 🎯 Aim
5+
The aim of this script is to perform the sorting process using the Radix Sort algortihm.
6+
7+
## 👉 Purpose
8+
The main purpose of this script is to show the implementation of Radix Sort algorithm on an unsorted array of elements to make it a sorted one, with less time complexity than the merge sort, quick sort.
9+
10+
## 📄 Description
11+
Radix sort is the linear sorting algorithm that is used for integers. In Radix sort, there is digit by digit sorting is performed that is started from the least significant digit to the most significant digit.
12+
13+
The process of radix sort works similar to the sorting of students names, according to the alphabetical order. In this case, there are 26 radix formed due to the 26 alphabets in English. In the first pass, the names of students are grouped according to the ascending order of the first letter of their names. After that, in the second pass, their names are grouped according to the ascending order of the second letter of their name. And the process continues until we find the sorted list.
14+
15+
🔴 Examples:
16+
17+
```
18+
Constraints:
19+
arr[] -> array of unsorted elements.
20+
countingSort(arr, exp1) -> implementation of Counting Sort before Radix Sort.
21+
radixSort(arr) -> implementation of Radix sort.
22+
23+
Input:
24+
Array before implementing the Radix Sort...
25+
170 45 75 90 802 24 2 66
26+
27+
Radix Sort going on...
28+
29+
Output:
30+
After implementing Radix Sort algorithm...
31+
2 24 45 66 75 90 170 802
32+
```
33+
34+
## 📊 Flowchart
35+
```
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
43+
```
44+
45+
## 🧮 Algorithm
46+
The steps used in the sorting of radix sort are listed as follows -
47+
- First, we have to find the largest element (suppose max) from the given array. Suppose `x` be the number of digits in max. The `x` is calculated because we need to go through the significant places of all elements.
48+
- After that, go through one by one each significant place. Here, we have to use any stable sorting algorithm to sort the digits of each significant place.
49+
Now let's see the working of radix sort in detail by using an example.
50+
51+
To understand it more clearly, let's take an unsorted array and try to sort it using radix sort. It will make the explanation clearer and easier.
52+
53+
For the understanding of the algorithm let's take the above mentioned example,
54+
The Input array is given as,
55+
```
56+
[170, 45, 75, 90, 802, 24, 2, 66]
57+
```
58+
59+
## 💻 Input and Output
60+
- **Test Case 1 :**
61+
```
62+
Input Given :
63+
s = [1 , 3 , 0 , 5 , 8 , 5]
64+
f = [2 , 4 , 6 , 7 , 9 , 9]
65+
```
66+
67+
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Greedy/Activity%20Selection%20Problem/Images/asp-1.png)
68+
69+
- **Test Case 2 :**
70+
```
71+
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]
74+
```
75+
![](https://github.com/abhisheks008/PyAlgo-Tree/blob/main/Greedy/Activity%20Selection%20Problem/Images/asp-2.png)
76+
77+
## ⏰ Time and Space complexity
78+
- **Time Complexity :** `O(n)`.
79+
- **Space Complexity :** `O(1)`.
80+
81+
---------------------------------------------------------------
82+
## 🖋️ Author
83+
**Code contributed by, _Abhishek Sharma_, 2022 [@abhisheks008](github.com/abhisheks008)**
84+
85+
[![forthebadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/)

0 commit comments

Comments
 (0)