Skip to content
Data Structures and Algorithms / Linear Structures, Hashing, and the Sorting Toolkit

Linear-Time Sorting: Counting, Radix, and Bucket Sort

Every sorting algorithm covered so far — insertion sort, mergesort, heapsort, quicksort — decides the relative order of elements purely by comparing them, and it turns out no such algorithm can beat Θ(nlog⁡n)\Theta(n\log n) in the worst case, a fact this note proves first. But that lower bound has an escape hatch: if the keys being sorted have extra exploitable structure (bounded integer range, fixed-width digits, a known distribution), an algorithm that never compares two elements directly can sort in Θ(n)\Theta(n). This note proves the comparison lower bound, then builds the three classical linear-time sorts — counting sort, radix sort, and bucket sort — each exploiting a different kind of structure.

In this lesson

  1. Learning objectives
  2. The comparison-sort lower bound
  3. Counting sort
  4. Radix sort
  5. Bucket sort

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or explore the curriculum.