Deck 20: Recursion

Full screen (f)
exit full mode
Question
The speed and amount of memory available to modern computers diminishes the performance impact of recursion so much that inefficiency is no longer a strong argument against it.
Use Space or
up arrow
down arrow
to flip the card.
Question
Indirect recursion means that a function calls itself n number of times and then processing of the function starts from the first call.
Question
If a recursive algorithm does not contain a base case, it

A) returns 0 and stops
B) returns False and stops
C) uses up all available stack memory, causing the program to crash
D) reaches the recursive case and stops
E) None of these
Question
When recursion is used on a linked list, it will always display the contents of the list in reverse order.
Question
Any algorithm that can be coded with recursion can also be coded with an iterative structure.
Question
In a recursive solution, the base case is always the first case to be called.
Question
When a recursive function directly calls itself, this is known as direct recursion.
Question
A recursive function cannot call another function.
Question
A __________ function is one that calls itself.

A) dynamic
B) static
C) validation
D) recursive
E) None of these
Question
When function A calls function B which, in turn, calls function A, this is known as

A) direct recursion
B) indirect recursion
C) function swapping
D) perfect recursion
E) None of these
Question
Like a loop, a recursive function must have some method to control the number of times it repeats.
Question
The __________ of recursion is the number of times a recursive function calls itself.

A) level
B) breadth
C) type
D) depth
E) None of these
Question
The __________ algorithm uses recursion to sort a list.

A) shell sort
B) QuickSort
C) binary sort
D) red/black sort
E) None of these
Question
A recursive function is designed to terminate when it reaches its

A) return statement
B) closing curly brace
C) last parameter
D) base case
E) None of these
Question
A problem can be solved with recursion if it can be broken down into successive smaller problems that are the same as the overall problem.
Question
To solve a problem recursively, you must identify at least one case in which the problem can be solved without recursion.
Question
All mathematical problems are designed to be more efficient using recursive solutions.
Question
The QuickSort algorithm works on the basis of

A) three sublists
B) two sublists and a pivot
C) two pivots and a sublist
D) three pivots
E) None of these
Question
Recursive algorithms are less efficient than iterative algorithms.
Question
The programmer must ensure that a recursive function does not become

A) a static function
B) a virtual function
C) an endless loop
D) a dynamic function
E) None of these
Question
How many times will the following function call itself if 5 is passed as the argument?
Void showMessage(int n)
{
If (n > 0)
{
Cout << "Good day!" << endl;
ShowMessage(n - 1);
}
}

A) 1
B) 4
C) 5
D) An infinite number of times
Question
The QuickSort algorithm was developed in 1960 by

A) Bjarne Stroustrup
B) Tony Gaddis
C) C.A.R. Hoare
D) C.M. Turner
E) None of these
Question
How many times will the following function call itself if 5 is passed as the argument?
Void showMessage(int n)
{
If (n > 0)
{
Cout << "Good day!" << endl;
ShowMessage(n + 1);
}
}

A) 1
B) 4
C) 5
D) An infinite number of times
Question
The QuickSort algorithm is used to sort

A) lists stored in arrays or linear linked lists
B) tree data structures
C) randomly-ordered files
D) All of these
E) None of these
Question
Select all that apply. Which of the following problems can be solved using recursion?

A) computing factorials
B) finding the greatest common divisor of two numbers
C) doing a Binary Search
D) multiplying two numbers
E) traversing a linked list
Question
The following code is an example of a __________ recursive algorithm. int myRecursion(int array[], int first, int last, int val)
{
Int num;
If (first > last)
Return -1;
Num = (first + last)/2;
If (array[num] == val)
Return num;
If (array[num] < val)
Return myRecursion(array, num + 1, last, val);
Else
Return myRecursion(array, first, num - 1, val);
}

A) Towers of Hanoi
B) QuickSort
C) binary search
D) doubly linked list
E) None of these
Question
The recursive factorial function calculates the factorial of its parameter. Its base case is when the parameter is

A) returned
B) received
C) one
D) zero
E) None of these
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/27
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 20: Recursion
1
The speed and amount of memory available to modern computers diminishes the performance impact of recursion so much that inefficiency is no longer a strong argument against it.
True
2
Indirect recursion means that a function calls itself n number of times and then processing of the function starts from the first call.
False
3
If a recursive algorithm does not contain a base case, it

A) returns 0 and stops
B) returns False and stops
C) uses up all available stack memory, causing the program to crash
D) reaches the recursive case and stops
E) None of these
C
4
When recursion is used on a linked list, it will always display the contents of the list in reverse order.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
5
Any algorithm that can be coded with recursion can also be coded with an iterative structure.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
6
In a recursive solution, the base case is always the first case to be called.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
7
When a recursive function directly calls itself, this is known as direct recursion.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
8
A recursive function cannot call another function.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
9
A __________ function is one that calls itself.

A) dynamic
B) static
C) validation
D) recursive
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
10
When function A calls function B which, in turn, calls function A, this is known as

A) direct recursion
B) indirect recursion
C) function swapping
D) perfect recursion
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
11
Like a loop, a recursive function must have some method to control the number of times it repeats.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
12
The __________ of recursion is the number of times a recursive function calls itself.

A) level
B) breadth
C) type
D) depth
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
13
The __________ algorithm uses recursion to sort a list.

A) shell sort
B) QuickSort
C) binary sort
D) red/black sort
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
14
A recursive function is designed to terminate when it reaches its

A) return statement
B) closing curly brace
C) last parameter
D) base case
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
15
A problem can be solved with recursion if it can be broken down into successive smaller problems that are the same as the overall problem.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
16
To solve a problem recursively, you must identify at least one case in which the problem can be solved without recursion.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
17
All mathematical problems are designed to be more efficient using recursive solutions.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
18
The QuickSort algorithm works on the basis of

A) three sublists
B) two sublists and a pivot
C) two pivots and a sublist
D) three pivots
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
19
Recursive algorithms are less efficient than iterative algorithms.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
20
The programmer must ensure that a recursive function does not become

A) a static function
B) a virtual function
C) an endless loop
D) a dynamic function
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
21
How many times will the following function call itself if 5 is passed as the argument?
Void showMessage(int n)
{
If (n > 0)
{
Cout << "Good day!" << endl;
ShowMessage(n - 1);
}
}

A) 1
B) 4
C) 5
D) An infinite number of times
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
22
The QuickSort algorithm was developed in 1960 by

A) Bjarne Stroustrup
B) Tony Gaddis
C) C.A.R. Hoare
D) C.M. Turner
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
23
How many times will the following function call itself if 5 is passed as the argument?
Void showMessage(int n)
{
If (n > 0)
{
Cout << "Good day!" << endl;
ShowMessage(n + 1);
}
}

A) 1
B) 4
C) 5
D) An infinite number of times
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
24
The QuickSort algorithm is used to sort

A) lists stored in arrays or linear linked lists
B) tree data structures
C) randomly-ordered files
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
25
Select all that apply. Which of the following problems can be solved using recursion?

A) computing factorials
B) finding the greatest common divisor of two numbers
C) doing a Binary Search
D) multiplying two numbers
E) traversing a linked list
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
26
The following code is an example of a __________ recursive algorithm. int myRecursion(int array[], int first, int last, int val)
{
Int num;
If (first > last)
Return -1;
Num = (first + last)/2;
If (array[num] == val)
Return num;
If (array[num] < val)
Return myRecursion(array, num + 1, last, val);
Else
Return myRecursion(array, first, num - 1, val);
}

A) Towers of Hanoi
B) QuickSort
C) binary search
D) doubly linked list
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
27
The recursive factorial function calculates the factorial of its parameter. Its base case is when the parameter is

A) returned
B) received
C) one
D) zero
E) None of these
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 27 flashcards in this deck.