Deck 15: Recursion

Full screen (f)
exit full mode
Question
Consider the following definition of the recursive function print. What is the output of the following statement?
Print(4);
<strong>Consider the following definition of the recursive function print. What is the output of the following statement? Print(4);  </strong> A) 0 1 2 3 4 B) 1 2 3 4 C) 4 3 2 1 D) 4 3 2 1 0 <div style=padding-top: 35px>

A) 0 1 2 3 4
B) 1 2 3 4
C) 4 3 2 1
D) 4 3 2 1 0
Use Space or
up arrow
down arrow
to flip the card.
Question
A recursive function in which the last statement executed is the recursive call is called a(n) ____ recursive function.

A) direct
B) tail
C) indefinite
D) indirect
Question
Consider the accompanying definition of a recursive function. Which of the statements represents the base case?

A) Statements in Lines 1-6.
B) Statements in Lines 3 and 4.
C) Statements in Lines 5 and 6.
D) Statements in Lines 3, 4, and 5.
Question
The following is an example of a recursive function.
The following is an example of a recursive function.  <div style=padding-top: 35px>
Question
The following is a valid recursive definition to determine the factorial of a non-negative integer.
The following is a valid recursive definition to determine the factorial of a non-negative integer.  <div style=padding-top: 35px>
Question
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(8) << endl;

A) 4
B) 8
C) 72
D) 720
Question
Every call to a recursive function requires the system to allocate memory for the local variables and formal parameters.
Question
Consider the accompanying definition of a recursive function. Which of the statements represent the base case?

A) Statements in Lines 3 and 4
B) Statements in Lines 5 and 6
C) Statements in Lines 3-6
D) Statements in Lines 5-10
Question
A definition in which something is defined in terms of a smaller version of itself is called a(n) ____ definition.

A) step-wise
B) recursive
C) member-wise
D) iterative
Question
Tracing through ____ recursion is more tedious than tracing other recursive forms.

A) direct
B) indirect
C) tail
D) iterative
Question
To design a recursive function, you must determine the limiting conditions.
Question
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(10) << endl;

A) 10
B) 11
C) 100
D) 110
Question
With recursion, the base case must eventually be reduced to a general case.
Question
The ____ case is the case for which the solution to an equation is obtained directly.

A) general
B) base
C) direct
D) tail
Question
Consider the accompanying definition of a recursive function. Which of the statements represent the general case?

A) Statements in Lines 1-6
B) Statements in Lines 3 and 4
C) Statements in Lines 4, 5, and 6
D) Statements in Lines 5 and 6
Question
In a recursive function, the base case stops the recursion.
Question
You can use a recursive algorithm to find the largest element in an array.
Question
Consider the accompanying definition of a recursive function. Which of the statements represent the general case?

A) Statements in Lines 3-11
B) Statements in Lines 5-6
C) Statements in Lines 5-11
D) Statements in Lines 7-11
Question
A function is called ____ if it calls itself.

A) directly iterative
B) indirectly iterative
C) directly recursive
D) indirectly recursive
Question
Infinite recursions execute forever on a computer.
Question
Suppose that function A calls function B, function B calls function C, function C calls function D, and function D calls function A. Function A is then ____________________ recursive.
Question
Consider the accompanying definition of the recursive function mystery. Given the declaration: int alpha[5] = {1, 4, 5, 8, 9};
What is the output of the following statement?
Cout << mystery(alpha, 0, 4) << endl;

A) 1
B) 18
C) 27
D) 35
Question
Which of the following rules should you follow to solve the Tower of Hanoi problem?

A) Only two disks can be moved at a time.
B) You can remove disks only from the first needle.
C) The removed disk must be placed on a smaller disk.
D) A smaller disk can be placed on top of a larger disk.
Question
____ control structures use a looping structure, such as while, for, or do...while, to repeat a set of statements.

A) Iterative
B) Recursive
C) Procedural
D) Object
Question
The recursive algorithm must have one or more base cases, and the general solution must eventually be reduced to a(n) ____________________.
Question
Which of the following function headings can be used for a recursive definition of a function to calculate the nth Fibonacci number?

A) void rFibNum(int a, int b)
B) bool rFibNum(int a, int b)
C) bool rFibNum(int a, int b, int n)
D) int rFibNum(int a, int b, int n)
Question
If a function A calls a function B and function B calls function A, then function A is ____________________ recursive.
Question
Consider the following recursive definition, where n is a positive integer.
The value of F(3) is ____________________.
Consider the following recursive definition, where n is a positive integer. The value of F(3) is ____________________.  <div style=padding-top: 35px>
Question
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(5, 10) << endl;

A) 720
B) 5040
C) 5760
D) 10800
Question
Recursive algorithms are implemented using ____________________ functions.
Question
Consider the following definition of the recursive function mystery. <strong>Consider the following definition of the recursive function mystery.   What is the output of the following statement? Cout << mystery(6, 10) << endl;</strong> A) 13 B) 21 C) 40 D) 42 <div style=padding-top: 35px> What is the output of the following statement?
Cout << mystery(6, 10) << endl;

A) 13
B) 21
C) 40
D) 42
Question
If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have ____ recursion.

A) unlimited
B) indefinite
C) infinite
D) tail
Question
Consider the following code.
int fact(int num)
{
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
The function fact is an example of a(n) ____________________ recursive function.
Question
Which of the following solution methods would be the best choice for a mission control system?

A) Iterative
B) Direct recursive
C) Indirect recursive
D) Infinite recursive
Question
Which of the following solutions is easier to construct for the Tower of Hanoi problem?

A) Recursive
B) Iterative
C) Procedural
D) Step-by-step
Question
The ____________________ Fibonacci number in a sequence is the sum of the second and third Fibonacci numbers.
Question
If you execute an infinite recursive function on a computer, the function executes until the system runs out of ____________________.
Question
Consider the following definition of the recursive function mystery. What is the output of the following statement?
Cout << mystery(5) << endl;
<strong>Consider the following definition of the recursive function mystery. What is the output of the following statement? Cout << mystery(5) << endl;  </strong> A) 50 B) 65 C) 120 D) 180 <div style=padding-top: 35px>

A) 50
B) 65
C) 120
D) 180
Question
How many needles are used in the Tower of Hanoi problem?

A) one
B) two
C) three
D) four
Question
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(3, 7) << endl;

A) 10
B) 21
C) 42
D) 420
Question
In the Tower of Hanoi problem, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is ____________________.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/41
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 15: Recursion
1
Consider the following definition of the recursive function print. What is the output of the following statement?
Print(4);
<strong>Consider the following definition of the recursive function print. What is the output of the following statement? Print(4);  </strong> A) 0 1 2 3 4 B) 1 2 3 4 C) 4 3 2 1 D) 4 3 2 1 0

A) 0 1 2 3 4
B) 1 2 3 4
C) 4 3 2 1
D) 4 3 2 1 0
C
2
A recursive function in which the last statement executed is the recursive call is called a(n) ____ recursive function.

A) direct
B) tail
C) indefinite
D) indirect
B
3
Consider the accompanying definition of a recursive function. Which of the statements represents the base case?

A) Statements in Lines 1-6.
B) Statements in Lines 3 and 4.
C) Statements in Lines 5 and 6.
D) Statements in Lines 3, 4, and 5.
B
4
The following is an example of a recursive function.
The following is an example of a recursive function.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
5
The following is a valid recursive definition to determine the factorial of a non-negative integer.
The following is a valid recursive definition to determine the factorial of a non-negative integer.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
6
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(8) << endl;

A) 4
B) 8
C) 72
D) 720
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
7
Every call to a recursive function requires the system to allocate memory for the local variables and formal parameters.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
8
Consider the accompanying definition of a recursive function. Which of the statements represent the base case?

A) Statements in Lines 3 and 4
B) Statements in Lines 5 and 6
C) Statements in Lines 3-6
D) Statements in Lines 5-10
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
9
A definition in which something is defined in terms of a smaller version of itself is called a(n) ____ definition.

A) step-wise
B) recursive
C) member-wise
D) iterative
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
10
Tracing through ____ recursion is more tedious than tracing other recursive forms.

A) direct
B) indirect
C) tail
D) iterative
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
11
To design a recursive function, you must determine the limiting conditions.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
12
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(10) << endl;

A) 10
B) 11
C) 100
D) 110
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
13
With recursion, the base case must eventually be reduced to a general case.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
14
The ____ case is the case for which the solution to an equation is obtained directly.

A) general
B) base
C) direct
D) tail
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
15
Consider the accompanying definition of a recursive function. Which of the statements represent the general case?

A) Statements in Lines 1-6
B) Statements in Lines 3 and 4
C) Statements in Lines 4, 5, and 6
D) Statements in Lines 5 and 6
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
16
In a recursive function, the base case stops the recursion.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
17
You can use a recursive algorithm to find the largest element in an array.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
18
Consider the accompanying definition of a recursive function. Which of the statements represent the general case?

A) Statements in Lines 3-11
B) Statements in Lines 5-6
C) Statements in Lines 5-11
D) Statements in Lines 7-11
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
19
A function is called ____ if it calls itself.

A) directly iterative
B) indirectly iterative
C) directly recursive
D) indirectly recursive
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
20
Infinite recursions execute forever on a computer.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
21
Suppose that function A calls function B, function B calls function C, function C calls function D, and function D calls function A. Function A is then ____________________ recursive.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
22
Consider the accompanying definition of the recursive function mystery. Given the declaration: int alpha[5] = {1, 4, 5, 8, 9};
What is the output of the following statement?
Cout << mystery(alpha, 0, 4) << endl;

A) 1
B) 18
C) 27
D) 35
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following rules should you follow to solve the Tower of Hanoi problem?

A) Only two disks can be moved at a time.
B) You can remove disks only from the first needle.
C) The removed disk must be placed on a smaller disk.
D) A smaller disk can be placed on top of a larger disk.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
24
____ control structures use a looping structure, such as while, for, or do...while, to repeat a set of statements.

A) Iterative
B) Recursive
C) Procedural
D) Object
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
25
The recursive algorithm must have one or more base cases, and the general solution must eventually be reduced to a(n) ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following function headings can be used for a recursive definition of a function to calculate the nth Fibonacci number?

A) void rFibNum(int a, int b)
B) bool rFibNum(int a, int b)
C) bool rFibNum(int a, int b, int n)
D) int rFibNum(int a, int b, int n)
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
27
If a function A calls a function B and function B calls function A, then function A is ____________________ recursive.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
28
Consider the following recursive definition, where n is a positive integer.
The value of F(3) is ____________________.
Consider the following recursive definition, where n is a positive integer. The value of F(3) is ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
29
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(5, 10) << endl;

A) 720
B) 5040
C) 5760
D) 10800
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
30
Recursive algorithms are implemented using ____________________ functions.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
31
Consider the following definition of the recursive function mystery. <strong>Consider the following definition of the recursive function mystery.   What is the output of the following statement? Cout << mystery(6, 10) << endl;</strong> A) 13 B) 21 C) 40 D) 42 What is the output of the following statement?
Cout << mystery(6, 10) << endl;

A) 13
B) 21
C) 40
D) 42
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
32
If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have ____ recursion.

A) unlimited
B) indefinite
C) infinite
D) tail
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
33
Consider the following code.
int fact(int num)
{
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
The function fact is an example of a(n) ____________________ recursive function.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following solution methods would be the best choice for a mission control system?

A) Iterative
B) Direct recursive
C) Indirect recursive
D) Infinite recursive
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following solutions is easier to construct for the Tower of Hanoi problem?

A) Recursive
B) Iterative
C) Procedural
D) Step-by-step
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
36
The ____________________ Fibonacci number in a sequence is the sum of the second and third Fibonacci numbers.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
37
If you execute an infinite recursive function on a computer, the function executes until the system runs out of ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
38
Consider the following definition of the recursive function mystery. What is the output of the following statement?
Cout << mystery(5) << endl;
<strong>Consider the following definition of the recursive function mystery. What is the output of the following statement? Cout << mystery(5) << endl;  </strong> A) 50 B) 65 C) 120 D) 180

A) 50
B) 65
C) 120
D) 180
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
39
How many needles are used in the Tower of Hanoi problem?

A) one
B) two
C) three
D) four
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(3, 7) << endl;

A) 10
B) 21
C) 42
D) 420
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
41
In the Tower of Hanoi problem, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 41 flashcards in this deck.