java
In a recursive program, the number of times a method calls itself is known as the __________.
depth of recursion
When recursive methods directly call themselves, it is known as __________.
direct recursion
Which of the following problems can be solved recursively?
greatest common denominator binary search Towers of Hanoi All of these.
In the following code that uses recursion to find the factorial of a number, what is the base case? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }
if (n == 0) return 1;
The actions performed by the JVM that take place with each method call are sometimes referred to as __________.
overhead
A method that calls itself is a __________ method.
recursive
A recursive method must have which of the following?
some way to control the number of time it repeats
The Towers of Hanoi is a mathematical game that is often used in computer science textbooks to illustrate the power of recursion.
True
The recursive binary search algorithm is a good example of repeatedly breaking a problem down into smaller pieces until it is solved.
True
The __________ is at least one case in which a problem can be solved without recursion.
base case
In the following code that uses recursion to find the greatest common divisor of a number, what is the base case? public static int gcd(int x, int y) { if (x % y == 0) return y; else return gcd(y, x % y); }
if (x % y == 0) return y;
Without a base case, a recursive method will call itself only once and stop.
False
A method is called from the main method for the first time. It then calls itself seven times. What is the depth of recursion?
7
Given the following code that uses recursion to find the factorial of a number, how many times will the else clause be executed if n = 5? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }
5
Recursion is never absolutely required to solve a problem.
True
A recursive method can have only one base case.
False
The recursive case does not require recursion so it stops the chain of recursive calls.
False
Whereas a recursive algorithm might result in faster execution time, the programmer might be able to design an iterative algorithm faster.
False
To use recursion for a binary search, what is required before the search can proceed?
The array must be sorted.
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
True
Any problem that can be solved recursively can also be solved iteratively, with a loop.
True
In the __________, the problem must be reduced to a smaller version of the original problem.
recursive case
__________ occurs when method A calls method B which in turn calls method A.
indirect recusion
Recursion can be a powerful tool for solving repetitive problems and is an important topic in upper-level computer science courses.
True