Question 4
What is the time complexity of calculating the nth Fibonacci number using dynamic programming?
Question 5
Which of the following algorithms is efficient for calculating Fibonacci numbers, especially for large values of n?
Question 6
What is wrong with the below code?
int fib(int n)
{
int f[n + 2];
int i;
for (i = 2; i <= n; i++)
{
f[i] = f[i - 1] + f[i - 2];
}
return f[n];
}
Question 7
What is the value of F(6) when the value of F(0)= 0 and F(1)=1 in the Fibonacci sequence?
Question 8
What is the output of the below recursive code of the Fibonacci algorithm?
int fib(int n)
{
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
Question 9
What is the space used in the below Fibonacci program?
int fib(int n)
{
int f[n + 2];
int i;
f[0] = 0;
f[1] = 1;
for (i = 2; i <= n; i++) {
f[i] = f[i - 1] + f[i - 2];
}
return f[n];
}
Question 10
What should be the base condition for the below recursive code?
int fib(int n)
{
//Base condition
return fib(n - 1) + fib(n - 2);
}
There are 10 questions to complete.