Fibonacci sequence

David Medina
3 min readMay 20, 2021

--

Fibonacci sequence?

The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each Fibonacci number equals the sum of the preceding two numbers. If the sequence is F(n), where n is the first term in the sequence, the following equation obtains n = 0, where the first two terms are defined as 0 and 1 by convention:

F (0) = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 …

If we use n = 1, the first two terms are defined as 1 and 1 by default, and therefore:

F (1) = 1, 1, 2, 3, 5, 8, 13, 21, 34 …

The Fibonacci sequence is named after Leonardo Pisano, also known as Fibonacci, an Italian mathematician who lived from 1170–1250. Leonardo Pisano used the arithmetic series to illustrate problems based on a pair of breeding rabbits.

  • How many pairs of rabbits will be produced in a year? Beginning with a single pair, if in every month each pair bears a new pair which becomes productive from the second month on?” The result can be expressed numerically as 1, 1, 2, 3, 5, 8, 13, 21, 34 …

Interestingly enough, Fibonacci numbers are also of interest to biologists and physicists because they are frequently observed in various natural objects. For example, the branching patterns in trees and leaves, and sunflowers are all based on the Fibonacci sequence.

Fibonacci Recursion

Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result. Most loops can be rewritten in a recursive style, and in some functional languages, this approach to looping is the default.

A recursion function is a technique for iterating over an operation by having the function call itself repeatedly until it arrives in a result. In most functional languages this approach to looping is by default. However, JavaScript is a functional language that supports recursive functions, but you should be aware that most compilers in JavaScripts are not currently optimized to support them effectively.

While Recursion can be used in many different situations, it’s most effective when you need to call the same function repeatedly with different parameters from within a loop, but mostly for solving problems involving iterative branching, such as fractal math, sorting, or traversing the nodes of complex non-linear data structures.

Recursion functions are easy to test because they are easy to write, with a specific and consistent return value for any given input, and no side effects on external variable states. One reason recursion is favored in functional programming languages is that it allows for the construction of code that doesn’t require setting and maintaining a state with local variables.

--

--

No responses yet