Algorithm Analysis and Complexity

Lesson 2 of 20

Race four growth curves on one shared scale as n doubles from 4 to 16, then fill a step-count table for a thousand items.

The big picture

Counting the cost

Big-O answers one question: how does the work grow as the input grows? Get the shape right and the constants stop mattering.

The race that matters

For n = 1,000: O(1) does 1 step, O(log n) about 10, O(n) 1,000, O(n²) 1,000,000. Same data, wildly different bills.

Counting steps

Big-O drops constants and small terms: 3n + 50 is written O(n). Only the fastest-growing piece survives.

Nested = multiplied

Two loops over the same n multiply: n × n. That is why 4 people need 6 pairwise handshakes, not 8.

Halving = logarithm

Cut the problem in half every step and you get O(log n) — 1,000,000 items take about 20 halvings.

Space counts too

Memory gets its own Big-O: a running total is O(1) extra; a full copy of the input is O(n) auxiliary space.