← Algorithm Design learning pathAlgorithm Design · Module 8 of 10
Sorting and searching in depth
Compare sorting algorithms and their trade-offs.
📖 Key ideas
- Comparison sorts: bubble, insertion, selection (O(n²)); merge, heap, quick (O(n log n)).
- Lower bound for comparison sorting: Ω(n log n).
- Non-comparison sorts: counting, radix, bucket (linear under conditions).
- Stable sorts keep equal elements in order.
- Binary search variants find first/last occurrence or answer bounds.
💡 Real-life example: Choosing a sort is choosing transport: bicycle for a short trip (insertion), train for long distances (merge).
Stable sortKeeps equal elements' order
In-placeUses O(1) extra memory
Counting sortSorts by counting values
Lower boundBest possible complexity