Deck 15: Recursion
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/23
Play
Full screen (f)
Deck 15: 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
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
B
3
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
C
4
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 23 flashcards in this deck.
Unlock Deck
k this deck
5
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 23 flashcards in this deck.
Unlock Deck
k this deck
6
Any problem that can be solved recursively can also be solved iteratively, with a loop.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
7
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
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
8
Without a base case, a recursive method will call itself only once and stop.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
9
In a recursive program, the number of times a method calls itself is known as the __________.
A) call count
B) cyclic identity
C) method heap
D) depth of recursion
A) call count
B) cyclic identity
C) method heap
D) depth of recursion
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
10
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 23 flashcards in this deck.
Unlock Deck
k this deck
11
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 23 flashcards in this deck.
Unlock Deck
k this deck
12
Recursion is never absolutely required to solve a problem.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
13
Recursion can be a powerful tool for solving repetitive problems and is an important topic in upper-level computer science courses.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
14
A recursive method can have only one base case.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
15
In the __________, the problem must be reduced 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 23 flashcards in this deck.
Unlock Deck
k this deck
16
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 23 flashcards in this deck.
Unlock Deck
k this deck
17
The recursive case does not require recursion so it stops the chain of recursive calls.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
18
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 23 flashcards in this deck.
Unlock Deck
k this deck
19
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 23 flashcards in this deck.
Unlock Deck
k this deck
20
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 23 flashcards in this deck.
Unlock Deck
k this deck
21
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
{
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 23 flashcards in this deck.
Unlock Deck
k this deck
22
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
{
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 23 flashcards in this deck.
Unlock Deck
k this deck
23
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
{
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 23 flashcards in this deck.
Unlock Deck
k this deck