How do merge sort and quicksort work, and how do they differ?
Short answer
Both are divide and conquer. Merge sort halves and merges: always O(n log n), stable, using O(n) extra memory. Quicksort splits around a pivot: fast on average but O(n²) in the worst case.
3 points to say:
- Merge sort is stable, quicksort is not.
- Quicksort sorts in place and reads memory well.
- A random pivot avoids O(n²).
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.