Lesson 52 of 86IntermediatePro Interactive Lesson

Counting Sort and LSD Radix Sort

Compare counting by key with stable passes over digits starting at the least significant digit.

Core Intuition & How It Works

Counting sort and LSD radix sort bypass the O(n log n) comparison lower bound by indexing directly into key buckets or sorting digit by digit from least to most significant. When key range or digit count is small, they run in linear time.

In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.

Time & Space Complexity

MetricComplexity
Time ComplexityO(n + k) counting, O(d(n + b)) radix
Space ComplexityO(n + k)
Topic ChapterChapter 9: Sorting & Selection
Difficulty LevelIntermediate

Key Pattern to Recognize

Iterate backward when placing elements via cumulative counts in counting sort so equal keys stay stable—essential for LSD radix sort.

Common Pitfalls & Edge Cases

Using counting sort when key range k is huge compared to n, or failing to handle negative numbers via an offset.

Real-World & Technical Interview Applications

Sorting fixed-width integers, IP addresses, suffix array construction, and GPU parallel radix sorts.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.