def fib(n):(adsbygoogle = window.adsbygoogle || []).push({});

f0, f1, = 0, 1

for i in range(n - 1):

f0, f1 = f1, f0 + f1

return f1

It looks like it'd be linear, given there's only one loop, but when I plotted n against runtime, the relationship was quadratic, why?

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Why is the complexity of this code O(n^2)?

**Physics Forums | Science Articles, Homework Help, Discussion**