Fibonacci Sequence Recursion

Fibonacci Sequence Recursion

Mehmet Cambaz 2020-09-06 2 Comments

The Fibonacci sequence is one of the most famous formulas in mathematics. Each number in the sequence is the sum of the two numbers that precede it.

Blog Image 3

Beginning of this sequence is as below;

0 1 1 2 3 5 8 13 21 34 55 89 144 ……

Fibonacci numbers are strongly related to the golden ratio: Binet's formula expresses the nth Fibonacci number in terms of n and the golden ratio, and implies that the ratio of two consecutive Fibonacci numbers tends to the golden ratio as n increases

Blog Image 2
Blog Image 3

What is recursion?

Sometimes a problem is too difficult or too complex to solve because it is too big. If the problem can be broken down into smaller versions of itself, we may be able to find a way to solve one of these smaller versions and then be able to build up to a solution to the entire problem. This is the idea behind recursion; recursive algorithms break down a problem into smaller pieces which you either already know the answer to, or can solve by applying the same algorithm to each piece, and then combining the results.

Blog Image 3

Recursion is a computer programming technique involving the use of a procedure, subroutine, function, or algorithm that calls itself in a step having a termination condition so that successive repetitions are processed up to the critical step where the condition is met at which time the rest of each repetition is processed from the last one called to the first.

Calculation of Fibonacci Sequence using recursion

var fib = function(num) {

if (num === 1) {

return 0;

}

if (num === 2) {

return 1;

}

return fib (num - 1) + fib (num - 2);

}

blog

Mehmet Cambaz ( Software Engineer )

I am a new graduated software enginner. Currently i am more focused on developing myself on web and mobile programming but i also love learning new things about programming and computer science

Comments

Blog Image 11

Mehmet Cambaz

2020-09-06

First Comment :D

Blog Image 11

Mertel Aler

2020-09-15

Second comment :D

Leave a Comment

www.000webhost.com