Skip to content

Instantly share code, notes, and snippets.

@ellisandrews
Last active August 20, 2020 04:08
Show Gist options
  • Save ellisandrews/da28dac5de275e60c0189bc78c9d7546 to your computer and use it in GitHub Desktop.
Save ellisandrews/da28dac5de275e60c0189bc78c9d7546 to your computer and use it in GitHub Desktop.
Exponential time complexity
def nth_fibonacci_term(n: int) -> int:
"""Recursively finds the nth term in the Fibonacci sequence. Assumes positive n."""
# Base case -- The first two numbers of the sequence are {0, 1}
if n <= 2:
return n - 1
return nth_fibonacci_term(n - 1) + nth_fibonacci_term(n - 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment