Ch 15 - Recursion

¡Supera tus tareas y exámenes ahora con Quizwiz!

A ____ method is a method that calls itself. (a) Looping (b) Circular (c) Recursive (d) Reoccurring

(c) Recursive

Like ____, a recursive method must have some way to control the number of times it repeats. (a) A loop (b) Any method (c) A GUI method (d) A rumor

(a) A loop

The number of times that a method calls itself is known as the (a) Height of recursion (b) Depth of recursion (c) Widthofrecursion (d) Length of recursion

(b) Depth of recursion

A recursive method is a method that (a) Uses four-letter words to tell you when you have an error (b) Keeps recurring in your program code (c) Calls itself (d) Is a method that has a loop in it

(c) Calls itself

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

False

True/False Any problem that can be solved recursively can also be solved iteratively.

True

True/False: If Method A calls Method B which in turn calls method A, it is called indirect recursion

True

True/False: Recusrive algorithms are usually less efficient than iterative algorithms

True

Which of the following does the JVM not have to perform when a method is called? (a) Allocate memory for parameters (b) Store the address of the program location where to return after the method terminates (c) Terminate the calling program (d) Allocate memory for local variables

(c) Terminate the calling program

To solve a program recursively, you need to identify at least one case in which the problem can be solved without recursion—this is known as (a) The recursive case (b) The terminal case (c) The base case (d) The final case

(c) The base case

Which of the following cannot be programmed recursively? (a) Towers of Hanoi (b) Greatest Common Denominator (c) Binary Search (d) All of the above can be programmed recursively.

(d) All of the above can be programmed recursively

How many times will the following method call itself, if 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); } } (a) 1 (b) 9 (c) 10 (d) An infinite number of times

(d) An infinite number of ti

The depth of recursion is (a) The number of times that a method calls itself (b) The value returned from the last recursive call (c) The value that will terminate the recursive calls (d) There is no such term

(a) The number of times that a method calls itself

The actions that the JVM must performed any time a method is called is called (a) Stack frame (b) Overhead (c) Housekeeping (d) Method calls

(b) Overhead

Like a loop, a recursive method must have (a) A counter (b) Some way to control the number of times it repeats itself (c) A return statement (d) A predetermined number of times it will execute before terminating

(b) Some way to control the number of times it repeats itself


Conjuntos de estudio relacionados

Chapter 3: Understanding and Appreciating the Time Value of Money

View Set

6 - (Questions) Health Insurance Underwriting

View Set

Physiology Exam 2: Name 4 hormones involved in the hormonal control of metabolic fuel and describe what the target cell for these hormones is, the cells that produce the hormones and what function changes in the target cells.

View Set

Chapter 12: Illegal Drugs Questions

View Set