Math for coding interviews/Quadratic growth - n²

O(n²) Quadratic Time, Explained Visually

n² means n multiplied by itself. If n is 10, that is 100. If n is 100, that is 10,000. If n is 1,000, that is 1,000,000. The work grows as a square.

See it for yourself

Picture a grid of tiles. If one side has n tiles, the whole floor has n × n = n² tiles. A 10×10 grid has 100 tiles. A 100×100 grid has 10,000.

Quadratic growth - n²

n² means n multiplied by itself. If n is 10, that is 100. If n is 100, that is 10,000. If n is 1,000, that is 1,000,000. The work grows as a square.

25 squares

5 rows x 5 columns = 5² = 25 operations

Think of it this way: Comparing every person in a room to every other person for a secret handshake. 10 people = 100 handshakes. 100 people = 10,000 handshakes.

For algorithms: Nested loops typically mean O(n²). Two-pointer techniques and hash maps exist specifically to avoid this.

Real-world analogy

Comparing every person in a room to every other person for a secret handshake. 10 people = 100 handshakes. 100 people = 10,000 handshakes.

Why it matters in interviews

Nested loops typically mean O(n²). Two-pointer techniques and hash maps exist specifically to avoid this.

Where it shows up on the learning path