Exam 13: Recursion

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

In reality, if you execute an infinite recursive method on a computer, it will execute forever.

Free
(True/False)
4.8/5
(42)
Correct Answer:
Verified

False

Consider the following definition of a recursive method.public static int strange(int[] list, int first, int last) { If (first == last) Return list[first]; Else Return list[first] + strange(list, first + 1, last); }Given the declarationint[] beta = {2, 5, 8, 9, 13, 15, 18, 20, 23, 25};What is the output of the following statement?System.out.println(strange(beta, 4, 7));

Free
(Multiple Choice)
4.8/5
(34)
Correct Answer:
Verified

D

The general case of a recursive solution is the case for which the solution is obtained directly.

Free
(True/False)
4.9/5
(28)
Correct Answer:
Verified

False

A method is called directly recursive if it calls another recursive method.

(True/False)
4.8/5
(35)

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 declarationint[] alpha = {1, 4, 5, 8, 9};What is the output of the following statement?System.out.println(mystery(alpha, 0, 4));

(Multiple Choice)
4.8/5
(31)

A general case to a recursive algorithm must eventually reduce to a base case.

(True/False)
4.9/5
(36)

The limiting condition for a recursive method using a list might be the number of elements in the list.

(True/False)
4.9/5
(37)

The overhead associated with iterative methods is greater in terms of both memory space and computer time compared to the overhead associated with executing recursive methods.

(True/False)
4.8/5
(32)

The following is a valid recursive definition to determine the factorial of a non-negative integer.0! = 1 1! = 1 n! = n * (n - 1)! if n > 0

(True/False)
4.8/5
(41)

In the recursive algorithm for the nth Fibonacci number, there are ____ base case(s).

(Multiple Choice)
4.9/5
(34)

Consider the following definition of a recursive method. public static int foo(int n) //Line 1 { //Line 2 If (n == 0) //Line 3 Return 0; //Line 4 Else //Line 5 Return n + foo(n - 1); //Line 6 }Which of the statements represent the base case?

(Multiple Choice)
4.8/5
(30)

public static int func2(int m, int n) { If (n == 0) Return 0; Else Return m + func2(m, n - 1); }What is the output of func2(2, 3)?

(Multiple Choice)
4.9/5
(46)

If you are building a mission control system, ____.

(Multiple Choice)
4.8/5
(42)

A method that calls itself is an iterative method.

(True/False)
4.9/5
(40)

The process of solving a problem by reducing it to smaller versions of itself is called recursion.

(True/False)
4.8/5
(41)

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

(Multiple Choice)
4.9/5
(38)

There are two base cases in the recursive implementation of generating a Fibonacci sequence.

(True/False)
4.8/5
(33)

A recursive method in which the first statement executed is a recursive call is called a tail recursive method.

(True/False)
4.7/5
(33)

Using a recursive algorithm to solve the Tower of Hanoi problem, a computer that can generate one billion moves per second would take ____ years to solve the problem.

(Multiple Choice)
4.7/5
(41)

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(3)?

(Multiple Choice)
4.7/5
(40)
Showing 1 - 20 of 50
close modal

Filters

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