Deck 14: Recursion
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/24
Play
Full screen (f)
Deck 14: Recursion
1
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
True
2
Recursion can be a powerful tool for solving repetitive problems and is an important topic in upper-level computer science courses.
True
3
A method is called from the main method for the first time. It then calls itself seven times. What is the depth of recursion?
A) 1
B) 7
C) 8
D) 6
A) 1
B) 7
C) 8
D) 6
B
4
When recursive methods directly call themselves, it is known as
A) direct recursion
B) indirect recursion
C) basic recursion
D) static recursion
A) direct recursion
B) indirect recursion
C) basic recursion
D) static recursion
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
5
The recursive case does not require recursion so it stops the chain of recursive calls.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
6
__________ occurs when method A calls method B which in turn calls method
A)
A) Dynamic recursion
B) Linear recursion
C) Direct recursion
D) Indirect recusion
A)
A) Dynamic recursion
B) Linear recursion
C) Direct recursion
D) Indirect recusion
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
7
The __________ is at least one case in which a problem can be solved without recursion.
A) recursive case
B) base case
C) termination point
D) pont of absolution
A) recursive case
B) base case
C) termination point
D) pont of absolution
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
8
Any problem that can be solved recursively can also be solved iteratively, with a loop.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
9
Like a loop, a recursive method must have which of the following?
A) a statement that increments the control variable
B) a control variable initialized to a starting value
C) some way to control the number of time it repeats
D) All of these
A) a statement that increments the control variable
B) a control variable initialized to a starting value
C) some way to control the number of time it repeats
D) All of these
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
10
Without a base case, a recursive method will call itself only once and stop.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following problems can be solved recursively?
A) greatest common denominator
B) Towers of Hanoi
C) binary search
D) All of these.
A) greatest common denominator
B) Towers of Hanoi
C) binary search
D) All of these.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
12
In the __________, we must always reduce the problem to a smaller version of the original problem.
A) partition case
B) base case
C) lessening case
D) recursive case
A) partition case
B) base case
C) lessening case
D) recursive case
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
13
A recursive method can have only one base case.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
14
In a recursive program, the number of times a method calls itself is known as
A) the call count
B) the cyclic identity
C) the method heap
D) the depth of recursion
A) the call count
B) the cyclic identity
C) the method heap
D) the depth of recursion
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
15
Whereas a recursive algorithm might result in faster execution time, the programmer might be able to design an iterative algorithm faster.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
16
A method that calls itself is a __________ method.
A) recursive
B) redundant
C) binary
D) derived
A) recursive
B) redundant
C) binary
D) derived
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
17
Recursion is never absolutely required to solve a problem.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
18
The Towers of Hanoi is a mathematical game that is often used in computer science textbooks to illustrate the power of recursion.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
19
The recursive binary search algorithm is a good example of repeatedly breaking a problem down into smaller pieces until it is solved.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
20
The actions performed by the JVM that take place with each method call are sometimes referred to as
A) overhead
B) allocation
C) overflow
D) retention
A) overhead
B) allocation
C) overflow
D) retention
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
21
To use recursion for a binary search, what is required before the search can proceed?
A) The array must include only integers.
B) The array can only include numerical values.
C) The array must be sorted.
D) All of these are required.
A) The array must include only integers.
B) The array can only include numerical values.
C) The array must be sorted.
D) All of these are required.
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
22
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);
}
A) gcd(int x, int y)
B) if (x % y == 0)
Return y;
C) else
Return gcd(y, x % y);
D) Cannot tell from this code
public static int gcd(int x, int y)
{
If (x % y == 0)
Return y;
Else
Return gcd(y, x % y);
}
A) gcd(int x, int y)
B) if (x % y == 0)
Return y;
C) else
Return gcd(y, x % y);
D) Cannot tell from this code
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
23
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);
}
A) factorial(int n)
B) if (n == 0)
Return 1;
C) else
Return n * factorial(n - 1);
D) Cannot tell from this code
private static int factorial(int n)
{
If (n == 0)
Return 1;
Else
Return n * factorial(n - 1);
}
A) factorial(int n)
B) if (n == 0)
Return 1;
C) else
Return n * factorial(n - 1);
D) Cannot tell from this code
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck
24
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);
}
A) 3
B) 4
C) 5
D) 6
private static int factorial(int n)
{
If (n == 0)
Return 1;
Else
Return n * factorial(n - 1);
}
A) 3
B) 4
C) 5
D) 6
Unlock Deck
Unlock for access to all 24 flashcards in this deck.
Unlock Deck
k this deck