Let’s talk about Recursion.

What is the Fibonacci Sequence?

n = (n-1) + (n-2)
fib(n) = fib(n-1) + fib(n-2)
def fib(n)
return fib(n-1) + fib(n-2)
end
def fib(n)
#base case
if n <= 1
return n
end

return fib(n-1) + fib(n-2)
end
def fib(n)
#base case
if n <= 1
return n
end

return fib(n-1) + fib(n-2)
end
print fib(4)

Issues with Recursion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store