• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Quiz on Fibonacci Numbers

Question 1

What is the Fibonacci sequence?

  • A sequence of odd numbers

  • A sequence of even numbers

  • A sequence of prime numbers

  • A sequence of numbers where each number is the sum of the two preceding ones

Question 2

Choose the recursive formula for the Fibonacci series.(n>=1)

  • F(n) = F(n+1) + F(n+2)

  • F(n) = F(n) + F(n+1)

  • F(n) = F(n-1) + F(n-2)

  • F(n) = F(n-1) – F(n-2)

Question 3

Guess the next value of the Fibonacci sequence: 21, 34, 55, ___, 144.

  • 89

  • 63

  • 83

  • 43

Question 4

What is the time complexity of calculating the nth Fibonacci number using dynamic programming?

  • O(N)

  • O(logN)

  • O(2^N)

  • O(N^2)

Question 5

Which of the following algorithms is efficient for calculating Fibonacci numbers, especially for large values of n?

  • Brute-force recursion

  • Depth-First Search (DFS)

  • Sieve of Eratosthenes

  • Dynamic programming

Question 6

What is wrong with the below code?

C++
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];
}
  • we have not assigned the first and second value of the list

  • we have declared the arry of size n+2

  • the loop must be run till (i<n).

  • None

Question 7

What is the value of F(6) when the value of F(0)= 0 and F(1)=1 in the Fibonacci sequence?

  • 6

  • 5

  • 8

  • 13

Question 8

What is the output of the below recursive code of the Fibonacci algorithm?

C++
int fib(int n)
{
       if (n <= 1) return n;

        return fib(n - 1) + fib(n - 2);
}
  • Linear

  • Constant

  • Exponential

  • None

Question 9

What is the space used in the below Fibonacci program?

C++
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];
}
  • O(1)

  • O(LogN)

  • O(N)

  • O(N^2)

Question 10

What should be the base condition for the below recursive code?

C++
int fib(int n)
{
        //Base condition

    return fib(n - 1) + fib(n - 2);
}
  • if(n>=1) return 0;

  • if(n<=1) return 0;

  • if(n< 1 ) return n;

  • if(n<=1) return n; 

There are 10 questions to complete.

Last Updated :
Take a part in the ongoing discussion