Chapter 3 The Efficiency of Algorithms The Fibonacci sequence of numbers is defi
ID: 3784857 • Letter: C
Question
Explanation / Answer
Answer a)
Using the definition of F(n) for Fibonacii sequence we get
F(1)=1
F(2)=1
F(3)=2
F(4)=3
F(5)=5
F(6)=8
F(7)=13
F(8)=21
F(9)=34
F(10)=55
F(11)=89
F(12)=144
F(13)=233
F(14)=377
F(15)=610
F(16)=987
F(17)=1597
F(18)=2584
F(19)=4181
F(20)=6765
A simple program written in C language for recursive Fibonacci sequence is show below.
So using a recursive algorithm, we get F(20)=6765
#include<stdio.h>
int F(int n)
{
if(n==1 || n==2)
{
return 1;
}
else
return F(n-1)+F(n-2);
}
int main()
{
printf(" F(%d)=%d",20,F(20));
}
Answer b:
Using the formula in a calculator also, we get F(20) = 6765
Answer c:
Both the methods give the same answer. But in terms of elegance, recursive method looks neat and clear based on the definition of Fibonacci sequence. But for larger 'n' say 100, the recursion takes a long time to compute as all the previous terms need to be computed. Whereas the formula based method takes the same time no matter what the value of 'n' is . So the formula method is efficient irrespective of 'n'.
Answer d and e
As its not possible to upload an excel sheet here, just showing you the contents of the file. Its simple for entering using the recursion, but for the formula method , this is how its entered , where <cellname> is replaced by the name of cell like C1 , D2 etc whereever you entered the value of n.
=SQRT(5)/5*POWER((1+SQRT(5))/2,<cellname>)-SQRT(5)/5*POWER((1-SQRT(5))/2,<cellname>)
=============================
Hope this answers all the questions. Please rate the answer if you are happy with it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.