Why nested loops are O(n²)
An outer loop runs n times; for each of those, an inner loop runs n times. Every (i, j) pair is one unit of work — and the pairs fill an n × n grid. The area you light up is the operation count.
| n | 4 | 8 | 16 | 32 |
|---|---|---|---|---|
| n² | 16 | 64 | 256 | 1,024 |