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

Question 2 The third Fibonacci number is ____. the sum of the first two Fibonacc

ID: 3829695 • Letter: Q

Question

Question 2

The third Fibonacci number is ____.

the sum of the first two Fibonacci numbers

the sum of the last two Fibonacci numbers

the product of the first two Fibonacci numbers

the product of the last two Fibonacci numbers

1 points   

Question 3

Which of the following statements is NOT true about infinite recursion?

In theory, infinite recursion executes forever.

In reality, infinite recursion will lead to a computer running out of memory and abnormal termination of the program.

Methods that are indirectly recursive always lead to infinite recursion.

If recursive calls never lead to a base case, infinite recursion occurs.

1 points   

Question 4

public static int exampleRecursion (int n)
{
    if (n == 0)
         return 0;
    else
         return exampleRecursion(n - 1) + n * n * n;
}

Which of the following is an invalid call to the method in the accompanying figure?

exampleRecursion(-1)

exampleRecursion( 0)

exampleRecursion(1)

exampleRecursion(999)

1 points   

Question 5

Consider the following definition of a recursive method.

public static int recFunc(int num)
{
      if (num >= 10)
           return 10;
      else
           return num * recFunc(num + 1);
}

What is the output of the following statement?

System.out.println(recFunc(10));

10

110

This statement results in infinite recursion.

None of these

1 points   

Question 6

Consider the following definition of a recursive method.

public static int mystery(int[] list, int first, int last)
{
    if (first == last)
        return list[first];
    else
        return list[first] + mystery(list, first + 1, last);
}

Given the declaration

int[] alpha = {1, 4, 5, 8, 9};

What is the output of the following statement?

System.out.println(mystery(alpha, 0, 4));

1

18

27

32

the sum of the first two Fibonacci numbers

the sum of the last two Fibonacci numbers

the product of the first two Fibonacci numbers

the product of the last two Fibonacci numbers

Explanation / Answer

Question 2

The third Fibonacci number is ____.

Ans)the sum of the first two Fibonacci numbers

_______________

Question 3

Which of the following statements is NOT true about infinite recursion?

Ans)Methods that are indirectly recursive always lead to infinite recursion.

_______________

Question 4

public static int exampleRecursion (int n)
{
    if (n == 0)
         return 0;
    else
         return exampleRecursion(n - 1) + n * n * n;
}

Which of the following is an invalid call to the method in the accompanying figure?

Ans)exampleRecursion(-1)

__________________

Question 5

Consider the following definition of a recursive method.

public static int recFunc(int num)
{
      if (num >= 10)
           return 10;
      else
           return num * recFunc(num + 1);
}

What is the output of the following statement?

System.out.println(recFunc(10));

Ans)10

Reason

As we are passing the value 10(recFunc(10)) to the function as input.The statement ( if (num >= 10) ) in the recursive function will be executed,.so it return the value 10.

______________________

Question 6

Consider the following definition of a recursive method.

public static int mystery(int[] list, int first, int last)
{
    if (first == last)
        return list[first];
    else
        return list[first] + mystery(list, first + 1, last);
}

Given the declaration

int[] alpha = {1, 4, 5, 8, 9};

What is the output of the following statement?

System.out.println(mystery(alpha, 0, 4));

Ans)27

Reason:

alpha[0]+alpha[1]+alpha[2]+alpha[3]+alpha[4]=1+4+5+8+9=27

Each time the value of first will be incremented by 1 till the value of first is equal to last(Which is 4).

_______________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote