Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have no idea about this question. Please solve this question. Algorithm 1.7 (n

ID: 3736561 • Letter: I

Question

I have no idea about this question. Please solve this question.

Algorithm 1.7 (nth Fibonacci Term, Iterative) is clearly linear in n, but is it a linear-time algorithm? In Section 1.3.1 we defined the input size as the size of the input. In the case of the nth Fibonacci term, n is the input, and the number of bits it takes to encode n could be used as the input size. Using this measure, the size of 64 is lg 64 = 6, and the size of 1,024 is lg 1,024 10. Show that Algorithm 1.7 is exponential-time in terms of its input size. Show further that any algorithm for computing the nth Fibonacci term must be an exponential-time algorithm because the size of the output is exponential in the input size.

Explanation / Answer

// C# program for Fibonacci Series

// using Recursion

using System;

public class GFG

{

    public static int Fib(int n)

    {

        if (n <= 1)

        {

            return n;

        }

        else

        {

            return Fib(n - 1) + Fib(n - 2);

        }

    }

         

    // driver code

    public static void Main(string[] args)

    {

        int n = 9;

        Console.Write(Fib(n));

    }

}

// C# program for Fibonacci Series

// using Recursion

using System;

public class GFG

{

    public static int Fib(int n)

    {

        if (n <= 1)

        {

            return n;

        }

        else

        {

            return Fib(n - 1) + Fib(n - 2);

        }

    }

         

    // driver code

    public static void Main(string[] args)

    {

        int n = 9;

        Console.Write(Fib(n));

    }

}