Loops in motion
Watch five classic loops run step by step: each step is a square, and the shape they draw is the Big-O.
Loop
1count = 0 2for i in range(n): 3 for j in range(i + 1, n): 4 if a[i] + a[j] == target: 5 count += 1 6return count
1/30
330471642613364985176367
target = 69. Check every pair i < j.
Counted steps0O(n²)
At the end28n = 8
A triangle, half an n × n square: quadratic.
O(n²): at n = 8 it is 28 steps. Double n and see: a row doubles, a triangle grows about 4×, the halving column grows by one.
How it's calculated · assumptions
Counted step = one comparison, probe or write. Small arrays so every step is visible; the shapes (and curves) are what scale.