MEPX
Chapter 2 of 12All chapters

Chapter 2 of 12

Reading Big O

Drop the constants, keep the fastest growing term.

The rules

Keep the term that grows fastest and throw away constants and smaller terms. So 3n + 50 is O(n), and n squared plus n is O(n squared).

  • Sequential loops add, so n plus n is still O(n).
  • Nested loops multiply, so a loop inside a loop over the same input is O(n squared).

What n means

Always say what n counts: rows, characters, nodes, pixels. Two inputs get two letters, as in O(n times m) for comparing two lists.