Yes We can do the same with recursion as well.
Code snippet:
def fibonacci_sequence(nterms):
# Base case if nterms == 1: return 1 if nterms == 0: return 0 # recursive call return fibonacci_sequence(nterms-1) + fibonacci_sequence(nterms-2)
We can do memomization here as well because here we are doing many rework as well
Some comments have been hidden by the post's author - find out more
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes We can do the same with recursion as well.
Code snippet:
def fibonacci_sequence(nterms):
We can do memomization here as well because here we are doing many rework as well