DSA, Database System & Operating System β Sorting, Searching, and Graphs, NEC licence examination syllabus (Nepal Engineering Council).
One divides and conquers. The other never even compares elements directly.
IdeaDivide the list in half repeatedly until each piece has 1 element, then merge sorted halves back together, always O(n log n) regardless of input order.
TradeoffNeeds extra memory for the merging step β not "in-place" the way some other sorts are.
IdeaSort numbers digit by digit, starting from the LEAST significant digit, using a stable sort (like counting sort) at each digit position.
Why it's differentNever directly compares two whole numbers against each other β this is what lets it beat the O(n log n) comparison-sort limit, achieving O(nk) for k digits.
The complexity comes from multiplying two independent quantities, and separating them makes it memorable rather than a fact to recall.
Merging two sorted halves into one cannot be done in place without either shifting elements (expensive) or complex bookkeeping. The straightforward implementation writes into a temporary array of size n and copies back.
CostO(n) extra memory, which rules it out where space is tight and makes heap sort preferable there.
Buys: stabilityTaking from the left half when values are equal preserves the original order of equal elements.
Buys: sequential accessMerging reads each run front to back, needing no random access β which is exactly why external sorting is built on merge sort.
Radix sort appears to beat the proven lower bound for sorting. It does not, and the resolution is worth stating.
The O(n log n) bound applies to comparison-based sorts β algorithms whose only operation on the data is comparing two elements. Radix sort never compares anything; it distributes items into buckets by digit. It sidesteps the bound by using extra information β that the keys are numbers with a fixed number of digits β rather than by being a cleverer comparison sort.Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Loadingβ¦