Sorting Algorithms
Arrange data in order — and why the choice of algorithm matters.
Easy
| Algorithm | Best | Average | Worst | Stable | Extra memory |
|---|---|---|---|---|---|
| Bubble | yes | ||||
| Insertion | yes | ||||
| Merge | yes | ||||
| Quick | no | ||||
| Heap | no |
A stable sort keeps equal items in their original order. Real libraries use hybrids like Timsort (Python, Java objects) and introsort (C++).
Sub-topics (3)
Bubble Sort
Repeatedly swap adjacent out-of-order elements until the list is sorted.
Beginner♥ 0🔖 0💬 0
Merge Sort
Divide the list in half, sort each half, then merge — always O(n log n).
Intermediate♥ 0🔖 0💬 0
Quick Sort
Pick a pivot, partition smaller and larger elements around it, and recurse.
Intermediate♥ 0🔖 0💬 0
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.