← 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

AlgorithmAverageWorstStable?
Bubble / InsertionO(n²)O(n²)Yes
SelectionO(n²)O(n²)No
Merge sortO(n log n)O(n log n)Yes
Quick sortO(n log n)O(n²)No
Heap sortO(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.