Created
April 14, 2020 19:13
-
-
Save Sasszem/08423d19507dcc532d017224f82f6c16 to your computer and use it in GitHub Desktop.
Showing exponential time complexity of the simple recursive method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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