Data Structure & Algorithms Fibonacci Series


Advertisements

Fibonacci series generates the subsequent number by adding two previous numbers. Fibonacci series starts from two numbers − F0 & F1. The initial values of F0 & F1 can be taken 0, 1 or 1, 1 respectively.

Fibonacci series satisfies the following conditions −

Fn = Fn-1 + Fn-2

Hence, a Fibonacci series can look like this −

F8 = 0 1 1 2 3 5 8 13

or, this −

F8 = 1 1 2 3 5 8 13 21

For illustration purpose, Fibonacci of F8 is displayed as −

Fibonacci Animation

Fibonacci Iterative Algorithm

First we try to draft the iterative algorithm for Fibonacci series.

Procedure Fibonacci(n)
   declare f0, f1, fib, loop 
   
   set f0 to 0
   set f1 to 1
   
   display f0, f1
   
   for loop ← 1 to n
   
      fib ← f0 + f1   
      f0 ← f1
      f1 ← fib

      display fib
   end for
	
end procedure

To know about the implementation of the above algorithm in C programming language, click here.

Fibonacci Recursive Algorithm

Let us learn how to create a recursive algorithm Fibonacci series. The base criteria of recursion.

START
Procedure Fibonacci(n)
   declare f0, f1, fib, loop 
   
   set f0 to 0
   set f1 to 1
   
   display f0, f1
   
   for loop ← 1 to n
   
      fib ← f0 + f1   
      f0 ← f1
      f1 ← fib

      display fib
   end for

END

To see the implementation of above algorithm in c programming language, click here.

Useful Video Courses


Video

Azure Data Lake Online Training

42 Lectures 1.5 hours

Ravi Kiran

Video

Data Structure Online Training

141 Lectures 13 hours

Arnab Chakraborty

Video

Oracle Data Guard Online Training

26 Lectures 8.5 hours

Parth Panjabi

Video

Big Data & Hadoop Online Training

65 Lectures 6 hours

Arnab Chakraborty

Video

Python with Data Science

Best Seller

75 Lectures 13 hours

Eduonix Learning Solutions

Video

Mathematics for Data Science and Machine Learning using R

64 Lectures 10.5 hours

Eduonix Learning Solutions

Advertisements