Solving Problems & Big-O in Python
Chapter 33: Solving Problems & Big-O
4 short lessons, with 3D animations, quizzes and coding tasks.
The lessons
How to solve a problem: a method that always works
An algorithm is a step-by-step recipe that turns an input into the right output, and a good one does it without wasted work.
Counting steps: O(1), O(n) and O(n²)
Big-O describes how the number of steps grows as n grows, keeping only the part that matters for big n.
Halving: O(log n) and O(n log n)
Log₂ n is how many times you can halve n before reaching 1, and an algorithm that halves its work each step is O(log n).
Memory, and what Python's own operations cost
Every solution costs time and memory, and many of Python's one-line operations hide a loop, so count both before you choose.