INTERMEDIATEFrequently Tested 4 min read 5 views
Non-Comparison Linear Sorting (Counting, Radix, Bucket) & O(n) Order Statistics
Beating the Omega(n log n) decision-tree bound with key-indexed Counting Sort, LSD Radix Sort stability requirement, Bucket Sort expected O(n), and deterministic O(n) Median-of-Medians.
1. Why Counting, Radix & Bucket Sort Beat
The lower bound () applies only to comparison-based decision trees.
- Counting Sort ( time & space): Counts frequencies in , computes prefix sums , and iterates the input array right-to-left ( down to ) to preserve stability!
- LSD Radix Sort (): Sorts digit-by-digit from Least Significant Digit (LSD) to Most Significant Digit using a STABLE subroutine (Counting Sort). (If the inner digit sort is unstable,
[21, 19]after units pass[19, 21]could corrupt tie-order on tens!) - Bucket Sort: Assumes uniform/smooth input over , distributes into buckets, sorts each bucket via Insertion Sort: , worst-case if all keys collide in 1 bucket.
2. Finding the -th Smallest Element (Order Statistics)
- Randomized QuickSelect: Recurses on only ONE side of the pivot: , worst-case .
- Deterministic Median-of-Medians (BFPRT, Groups of ): Partition into groups of , find median of each group, recursively find pivot median of those medians. At least elements are and , so worst-case recurrence is:
(Why groups of and NOT ? With groups of , because , whereas !)
Key Formulas Summary
Radix Sort Optimal Base Selection for n Integers in [0, n^c - 1]
Note: Choosing base b = n sorts n integers bounded by n^3 in O(3 * (n + n)) = Theta(n) deterministic time!
Simultaneous Min AND Max Optimal Tournament Comparisons
Note: Compare elements in pairs first (n/2 comps), then compare winners with max and losers with min!
#Algorithms#Counting Sort#Radix Sort#Bucket Sort#QuickSelect#Median of Medians
Practice Questions on This Chapter (1)
Q1GATE CS 2021 Set-2MCQMEDIUM
+2M • -0.67
What is the worst-case time complexity to sort integers lying in the range in the RAM model?
⚡ Click an option above to verify instantly