← All concepts
TechnologyAlgorithms
Algorithms & complexity
Searching, sorting, and how to read Big-O time complexity.
Big-O in one line
Big-O describes how the work grows with the input size *n*, ignoring constants. From fastest to slowest: O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ).
Searching
- Linear search: check each element in turn — O(n). Works on unsorted data.
- Binary search: repeatedly halve a sorted array — O(log n). The data must be sorted first.
Sorting
| Algorithm | Average | Worst | Stable? |
|---|---|---|---|
| Bubble / Insertion | O(n²) | O(n²) | Yes |
| Selection | O(n²) | O(n²) | No |
| Merge sort | O(n log n) | O(n log n) | Yes |
| Quick sort | O(n log n) | O(n²) | No |
| Heap sort | O(n log n) | O(n log n) | No |
Tip:A *stable* sort keeps equal elements in their original order — it matters when sorting by one key after another.
Related:Data structures
