Exam 16: Recursion

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

How many times will the following method call itself if the value 10 is passed as the argument? Public static void message(int n) { If (n < 0) { System.out.println("Print this line.\n"); Message(n + 1); } }

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

A

Look at the following method: public static int test2(int x, int y) { If ( x < y) { Return -5; } Else { Return (test2(x - y, y + 5) + 6); } } What is returned for test2(18,5)?

Free
(Multiple Choice)
4.9/5
(43)
Correct Answer:
Verified

C

Look at the following pseudocode algorithm: Algorithm gcd(x, y) If (x < y) Gcd (y, x) Else If (y = 0) Return x Else Return gcd(y, x mod y) End gcd What is the base case for the algorithm gcd?

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

B

A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.

(True/False)
4.8/5
(38)

Look at the following pseudocode algorithm: algorithm Test14(int x) If (x < 8) Return (2 * x) Else Return (3 * Test14(x - 8) + 8) End Test14 What is the recursive case for the algorithm?

(Multiple Choice)
5.0/5
(46)

If the base case in a recursive method is never reached:

(Multiple Choice)
4.9/5
(37)

Look at the following pseudocode algorithm: algorithm Test14(int x) If (x < 8) Return (2 * x) Else Return (3 * Test14(x - 8) + 8) End Test14 What is the base case for the algorithm?

(Multiple Choice)
4.9/5
(35)

The number of times that a method calls itself is known as the:

(Multiple Choice)
4.8/5
(31)

Look at the following pseudocode algorithm: Algorithm gcd(x, y) If (x < y) Gcd (y, x) Else If (y = 0) Return x Else Return gcd(y, x mod y) End gcd What is returned from gcd(60, 24)?

(Multiple Choice)
4.8/5
(37)

Any problem that can be solved recursively can also be solved iteratively.

(True/False)
4.8/5
(38)

Recursive algorithms are usually less efficient than:

(Multiple Choice)
4.9/5
(48)

Like ________, a recursive method must have some way to control the number of times it repeats.

(Multiple Choice)
4.9/5
(39)

This term is used for methods that directly call themselves.

(Multiple Choice)
4.8/5
(35)

Look at the following pseudocode algorithm: Algorithm Test3(int a, int b) If (a < b) Return 5 Else if ( a == b) Return -5; Else Return (a + Test3(a - 1, b) End Test3 What is the base case for the algorithm?

(Multiple Choice)
4.7/5
(43)

Look at the following pseudocode algorithm: Algorithm Test3(int a, int b) If (a < b) Return 5 Else if ( a == b) Return -5; Else Return (a + Test3(a - 1, b) End Test3 What is the recursive case for the algorithm?

(Multiple Choice)
4.8/5
(37)

Look at the following pseudocode algorithm: algorithm Test14(int x) If (x < 8) Return (2 * x) Else Return (3 * Test14(x - 8) + 8) End Test14 What is the depth of Test14(16)?

(Multiple Choice)
4.9/5
(44)

The depth of recursion is:

(Multiple Choice)
4.8/5
(37)

Look at the following method: public static int test2(int x, int y) { If ( x < y) { Return -5; } Else { Return (test2(x - y, y + 5) + 6); } } What is the depth of test2(18,5)?

(Multiple Choice)
4.9/5
(39)

Look at the following pseudocode algorithm: algorithm Test14(int x) If (x < 8) Return (2 * x) Else Return (3 * Test14(x - 8) + 8) End Test14 What is the depth of Test14(7)?

(Multiple Choice)
4.9/5
(34)

Unlike a loop, a recursive method does not require code to stop it from repeating.

(True/False)
4.9/5
(31)
Showing 1 - 20 of 42
close modal

Filters

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