Exam 13: Recursion

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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?

(Multiple Choice)
4.9/5
(28)

public static int func2(int m, int n) { If (n == 0) Return 0; Else Return m + func2(m, n - 1); }What is the limiting condition of the code in the accompanying figure?

(Multiple Choice)
4.8/5
(37)

If every recursive call results in another recursive call, then the recursive method (algorithm) is said to have infinite recursion.

(True/False)
4.8/5
(41)

The third Fibonacci number is ____.

(Multiple Choice)
4.9/5
(33)

What is the first step in the Tower of Hanoi recursive algorithm?

(Multiple Choice)
4.8/5
(32)

In the base case of a recursive solution, the solution is obtained through a call to a smaller version of the original method.

(True/False)
4.8/5
(38)

public static int func2(int m, int n) { If (n == 0) Return 0; Else Return m + func2(m, n - 1); }Which of the following statements about the code in the accompanying is always true?

(Multiple Choice)
4.9/5
(39)

A method that calls another method and eventually results in the original method call is called indirectly recursive.

(True/False)
4.8/5
(31)

A program will terminate after completing any particular recursive call.

(True/False)
4.9/5
(41)

The following is an example of a recursive method.public static int recFunc(int x) { return (nextNum(nextNum(x))); }where nextNum is method such that nextNum(x) = x + 1.

(True/False)
4.9/5
(29)

Every recursive call has its own code.

(True/False)
5.0/5
(35)

Which of the following statements describe the base case of a recursive algorithm? (i) F(0) = 0; (ii) F(x) = 2 * F(x - 1); (iii) if (x == 0) F(x) = 5 + x;

(Multiple Choice)
4.8/5
(35)

The base case starts the recursion.

(True/False)
4.8/5
(36)

You can think of a recursive method as having unlimited copies of itself.

(True/False)
4.8/5
(40)

public static int exampleRecursion (int n) { If (n == 0) Return 0; Else Return exampleRecursion(n - 1) + n * n * n; }What is the output of exampleRecursion(0)?

(Multiple Choice)
4.9/5
(33)

public static int exampleRecursion (int n) { If (n == 0) Return 0; Else Return exampleRecursion(n - 1) + n * n * n; }What does the code in the accompanying figure do?

(Multiple Choice)
4.8/5
(31)

Assume there are four methods A, B, C, and D. If method A calls method B, method B calls method C, method C calls method D, and method D calls method A, which of the following methods is indirectly recursive?

(Multiple Choice)
4.9/5
(38)

A recursive solution is always a better alternative to an iterative solution.

(True/False)
4.9/5
(41)

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(8));

(Multiple Choice)
4.8/5
(42)

public static int exampleRecursion (int n) { If (n == 0) Return 0; Else Return exampleRecursion(n - 1) + n * n * n; }How many base cases are in the code in the accompanying figure?

(Multiple Choice)
4.8/5
(36)
Showing 21 - 40 of 50
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)