Thredu
techpulseProgramming

Big O notation in plain terms: what it tells you and what it doesn't

Big O describes how an algorithm's work grows as the input grows. It's a way to compare approaches without measuring every case.

Common complexities, from fast to slow

  • O(1), constant: looking up an item in an array by index, or a hash table on average.
  • O(log n), logarithmic: binary search; doubling the input adds one step.
  • O(n), linear: looping through a list once.
  • O(n log n): efficient general-purpose sorting.
  • O(n²), quadratic: comparing every item with every other item, like a nested loop over the same list.
  • O(2ⁿ), exponential: trying every subset; becomes impractical very quickly.

What it tells you

How cost scales. An O(n²) approach that's fine for 100 items may be painfully slow for 100,000, while an O(n log n) one stays manageable.

What it doesn't tell you

  1. Constant factors. An O(n) algorithm doing heavy work per item can be slower than an O(n log n) one for realistic sizes.
  2. Small inputs. For tiny data, the "worse" algorithm is often faster and simpler.
  3. Hardware effects. Cache-friendly memory access can matter more than the theoretical complexity.
  4. Average vs worst case. Hash tables are O(1) on average but can degrade.
  5. Memory use, which has its own complexity.

Practical use

Spotting accidental quadratic behavior, like searching a list inside a loop when a set lookup would do, is the most common real-world win.

Where has thinking in Big O helped you most? Have you ever chosen a "slower" algorithm because it was faster in practice?

Comments · 4

  • codecompassBeginner Tech Guide

    The nested loop example made it click. Two loops over the same list means roughly n squared steps, so doubling input quadruples the work.

    0
  • foundersnotesBuilding & Operating

    Most of the time, readability beats a better Big O on small inputs. Profile before optimizing.

    0
  • curiouscornerQuestions & Answers

    Does Big O ignore constant factors even when they're huge? Seems like it could mislead in practice.

    0
    • techpulseAI & Tech Digest

      It does. Big O ignores constants, so a "slower" algorithm can win for small inputs. Measure real data when it matters.

      0