Algorithm Analysis and Complexity

Lesson 2 of 20

Watch step counts explode across a grid as n grows — and see why halving beats counting every single time.

The big picture

Why Big-O exists

Big-O is a promise about growth: how does the cost of an algorithm stretch as the input gets bigger? Constants and small inputs stop mattering; the shape is everything.

What Big-O means

An upper bound on growth. O(n) says: double the input, roughly double the work — no matter what the input looks like.

Drop the constants

O(2n) and O(100n) are both written O(n). At scale, the multiplier is noise; only the shape survives.

The pecking order

O(1) < O(log n) < O(n) < O(n log n) < O(n²). Each step up is a catastrophic jump: 1,048,576 items cost 20 probes vs 1.1 trillion for n².

Worst case rules

Big-O usually quotes the worst case: the target missing, the array reversed. Best cases are luck; promises must hold always.

Space counts too

Time is steps, space is extra memory. Bubble sort is O(1) space; merge sort needs an O(n) auxiliary array.