# Quadratic

**Runtime** $\mathcal{O}(n^2) $ | Slow sorting O(n x n) Quadratic time

As we double `N`

the output would be multiplied by `4`

, which is `2`

squared.

Typically associated with nesting loops.

```
count = 0
for i in range(0, N):
for j in range(i+1, N):
if a[i] + a[j] == 0:
count += 1
```

```
from stopwatch import Stopwatch
def quadratic_run_time(N):
i = 1
total_operations = 0
while i < N:
j = 1
while j < N:
total_operations += 1
j += 1
i += 1
return total_operations
if __name__ == '__main__':
input_sizes = [100, 200, 400, 800, 1600, 3200]
for input_size in input_sizes:
timer = Stopwatch()
total_operations = quadratic_run_time(input_size)
print(input_size, total_operations, timer.elapsed_time())
```

What you should see from the output is as you double your input the runtime is multiplied by `4`

#### Reference

15:11 => 17:33