3. Complexity and mathBig-O and the master theorem
Big-O and the master theorem
Big-O is a shorthand for how an algorithm’s work grows as its input gets bigger. Instead of timing code on one machine, you ask: if the input doubles, does the work stay flat, double, or quadruple? O(n) means work grows in step with the input, O(n²) means doubling the input roughly quadruples it, and O(log n) means each doubling adds just one more step, like halving a phone book to find a name. Constants are dropped because at scale the shape of the curve dominates. The master theorem is a recipe for reading off the cost of divide-and-conquer algorithms like merge sort from how they split the problem and recombine the pieces.
In this lesson: A growth-curve plotter. The master theorem draws a recursion tree with work-per-level bars, so you see which case wins.