8000 add marks · bloomsky9/Algorithms-Explanation@3587c85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3587c85

Browse files
authored
add marks
1 parent 5937f76 commit 3587c85

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

en/Sorting Algorithms/Radix Sort

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Radix Sort
1+
# Radix Sort
22

33
The lower bound for Comparison based sorting algorithm (Merge Sort, Heap Sort, Quick-Sort .. etc) is `Ω(nLogn)`, i.e., they cannot do better than nLogn.
44

@@ -9,10 +9,11 @@ We can’t use counting sort because counting sort will take `O(n2)` which is wo
99

1010
Radix Sort is the answer. The idea of Radix Sort is to do digit by digit sort starting from least significant digit to most significant digit. Radix sort uses counting sort as a subroutine to sort.
1111

12-
The Radix Sort Algorithm
12+
## The Radix Sort Algorithm
1313

1414
Do following for each digit i where i varies from least significant digit to the most significant digit.
1515
Sort input array using counting sort (or any stable sort) according to the i’th digit.
16+
1617
Example:
1718

1819
Original, unsorted list:
@@ -31,13 +32,16 @@ Sorting by next digit (10s place) gives:
3132

3233
Sorting by the most significant digit (100s place) gives:
3334
`2, 24, 45, 66, 75, 90, 170, 802`
34-
What is the running time of Radix Sort?
35+
36+
## What is the running time of Radix Sort?
37+
3538
Let there be d digits in input integers. Radix Sort takes `O(d*(n+b))` time where b is the base for representing numbers, for example, for the decimal system, b is 10.
3639
What is the value of d? If `k` is the maximum possible value, then d would be `O(logb(k))`. So overall time complexity is `O((n+b) * logb(k))`. Which looks more than the
3740
time complexity of comparison-based sorting algorithms for a large k. Let us first limit k. Let k <= nc where c is a constant. In that case, the complexity becomes
3841
`O(n logb(n))`. But it still doesn’t beat comparison-based sorting algorithms.
3942

40-
Is Radix Sort preferable to Comparison based sorting algorithms like Quick-Sort?
43+
## Is Radix Sort preferable to Comparison based sorting algorithms like Quick-Sort?
44+
4145
If we have `log2n` bits for every digit, the running time of Radix appears to be better than Quick Sort for a wide range of input numbers. The constant factors hidden in
4246
asymptotic notation are higher for Radix Sort and Quick-Sort uses hardware caches more effectively. Also, Radix sort uses counting sort as a subroutine and counting sort
4347
takes extra space to sort numbers.

0 commit comments

Comments
 (0)
0