The Fibonacci sequence is the series of numbers starting from 0, 1 where each consecutive number N is the sum of the two previous numbers.

It goes…

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 31781…

Given a place in the sequence, how can we find the value of N?

This is Where Recursion Comes In

Image for post

Image Source

Recursion is a programming paradigm in which a function calls on itself. Here is an example of a recursive function.

function factorial(n) {
  if (n === 0) return 1
  return n * factorial(n - 1)
}
// factorial(5) => 5 * 4 * 3 * 2 * 1

As you might expect, recursive functions are usually written with a “base case” (n === 0) at which the function stops calling on itself.

#recursion #programming #optimization #algorithms #javascript

Recursively Finding the Nth Fibonacci Number
1.15 GEEK