Sorting
EasyAlgorithms
Sorting underpins many algorithmic techniques. Beyond knowing the standard algorithms, interviewers want you to recognize when counting sort beats comparison sort and when merge sort is preferable to quicksort.
AVG TIME
O(n log n)
SPACE
O(log n)
BEST
O(n log n)
WORST
O(n^2)
Step-by-Step Walkthrough
In Python
Math You Need For This
Merge sort: split a deck of 16 cards into halves, then quarters, then singles (log₂(16)=4 splits). Merge the singles into sorted pairs - 8 merges. Merge pairs into fours - 4 merges. Each round does n total work across 4 rounds = 4n = n log n.
Required concepts
Key math ideas
1 / 4
Interactive 3D Visualization
Brute Force vs Optimized
Watch It Run
Python Implementation
Now try it yourself
1 challenge with test cases and AI feedback
Practice Now
Complexity Analysis
Sorting
Next: Binary Search