Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 Calculate the Fibonacci numbers ( 2 0 pts ) The Fibonacci numbers are the numbers in the following integer sequence. 0 , 1 ,

2 Calculate the Fibonacci numbers(20pts)
The Fibonacci numbers are the numbers in the following integer sequence.
0,1,1,2,3,5,8,13,21,34,55,89,144,dots
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation:
Fn=Fn-1+Fn-2, where F0=0,F1=1
Discuss the correctness of the following algorithms that calculate Fibonacci numbers:
Algorithm 1
fib 1(n)
{
integer array f[n+1];
f[0]=0;
f[1]=1;
for (i=2 to n)
f[i]=f[i-1]+f[i-2]
return f[n];
}
Algorithm 2
fib 2(n)
{
if (n>1)
return fib 2(n-1)+ fib 2(n-2)
else if (n1)
return fib2(n)
}
Algorithm 3
fib 3(n)
{
a=0
b=1
if (n=0)
return a
for (i =2 to n)
{
c=a+b
b=c
a=b
}
return b;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions