Skip to content

Instantly share code, notes, and snippets.

@Sasszem
Created April 14, 2020 19:13
Show Gist options
  • Save Sasszem/08423d19507dcc532d017224f82f6c16 to your computer and use it in GitHub Desktop.
Save Sasszem/08423d19507dcc532d017224f82f6c16 to your computer and use it in GitHub Desktop.
Showing exponential time complexity of the simple recursive method
import timeit
def fib(n):
if n==1 or n==2:
return 1
return fib(n-1) + fib(n-2)
print(timeit.timeit("fib(10)", "from __main__ import fib", number=1, ))
print(timeit.timeit("fib(20)", "from __main__ import fib", number=1, ))
print(timeit.timeit("fib(30)", "from __main__ import fib", number=1, ))
print(timeit.timeit("fib(40)", "from __main__ import fib", number=1, ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment