Skip to content

Instantly share code, notes, and snippets.

View anirudhgiri's full-sized avatar

Anirudh Giri anirudhgiri

View GitHub Profile
@anirudhgiri
anirudhgiri / fib.py
Created January 19, 2020 16:49
Comparing two recursive approaches to print all fibonacci numbers to highlight the advantage of recursive memoization
#standard recursive function to find fibonacci numbers
#extremely slow. needs to find the value of all preceding fibonacci numbers each time
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
return fib(n-1)+fib(n-2)