Exam 14: Recursion
Exam 1: Introduction to Computer and C++ Programming56 Questions
Exam 2: C++ Basics57 Questions
Exam 3: More Flow of Control45 Questions
Exam 4: Procedural Abstraction and Functions That Return a Value53 Questions
Exam 5: Functions for All Sub Tasks54 Questions
Exam 6: Io Streams As an Introduction to Objects and Classes52 Questions
Exam 7: Arrays48 Questions
Exam 8: Strings and Vectors69 Questions
Exam 9: Pointers and Dynamic Arrays39 Questions
Exam 10: Defining Classes61 Questions
Exam 11: Friends, Overloaded Operators, and Arrays in Classes56 Questions
Exam 12: Separate Compilation and Namespaces41 Questions
Exam 13: Pointers and Linked Lists64 Questions
Exam 14: Recursion48 Questions
Exam 15: Inheritance53 Questions
Exam 16: Exception Handling47 Questions
Exam 17: Templates35 Questions
Exam 18: Standard Template Library59 Questions
Select questions type
A class member function may be recursive.
Free
(True/False)
4.9/5
(43)
Correct Answer:
True
How do you ensure that your function does not have infinite recursion?
Free
(Essay)
4.9/5
(35)
Correct Answer:
All recursive calls must lead to a stopping case.
In a recursive function, the statements) that invoke the function again are called the ______________.
Free
(Short Answer)
4.8/5
(34)
Correct Answer:
recursive calls
Recursive functions always execute faster than an iterative function.
(True/False)
4.9/5
(38)
The recursive definition of a Fibonacci Number is Fn) = Fn-1) + Fn-2), where F0)=1 and F1)=1. What is the value of Fib5)?
(Multiple Choice)
4.8/5
(40)
In the following function, how many recursive calls are there?
Void towerschar source, char dest, char help, int numDisks)
{
IfnumDisks<1)
{
Return;
}
Else
{
Towerssource,help,dest,numDisks-1);
Cout << "Move disk from " << source << " to " <<dest<<endl;
Towershelp,dest,source,numDisks-1);
}
}
(Multiple Choice)
4.8/5
(37)
If your program makes too many recursive function calls, your program will cause a ___________
(Multiple Choice)
4.9/5
(38)
To ensure that your function recurses correctly and the proper result is reached, you must ensure that
(Multiple Choice)
4.9/5
(29)
What is wrong with the following recursive function? It should print out the array backwards.
Void printint array[], int start, int size)
{
Ifstart == size)
Return;
Else
{
Printarray, start+1,size);
Cout << array[start] << endl;
}
}
(Multiple Choice)
4.8/5
(33)
What is the output of the following code fragment?
Int f1int x, int y)
{
Ifx<0 || y<0)
Return x-y;
Else
Return f1x-1,y) + f1x,y-1);
}
Int main)
{
Cout << f12,1)<<endl;
Return 0;
}
(Multiple Choice)
4.7/5
(38)
What is the output of the following code fragment?
Int f1int base, int limit)
{
Ifbase > limit)
Return -1;
Else
Ifbase == limit)
Return 1;
Else
Return base * f1base+1, limit);
}
Int main)
{
Cout << f12,4)<<endl;
Return 0;
}
(Multiple Choice)
4.9/5
(44)
The factorial of an integer is the product of that integer multiplied by all the positive non-zero integers less than that integer. So, 5! ! is the mathematical symbol for factorial) is 5 * 4 * 3*2*1. 4! is 4*3*2*1, so 5! could be written as 5*4!. So a recursive definition of factorial is n! is n*n-1)!, as long as n >1. 1! is 1. What is the stopping case for this function?
(Multiple Choice)
4.9/5
(42)
Every time a recursive function call is executed, a new __________ is put on the top of the stack.
(Multiple Choice)
4.9/5
(37)
What is the output of the following code fragment?
Int f1int n, int m)
{
Ifn < m)
Return 0;
Else ifn==m)
Return m+ f1n-1,m);
Else
Return n+ f1n-2,m-1);
}
Int main)
{
Cout << f11,4);
Return 0;
}
(Multiple Choice)
4.7/5
(37)
What is wrong with the following recursive function? It should print out the array backwards.
Void printint array[], int start, int size)
{
Ifstart < size)
Return;
Else
{
Printarray, start+1,size);
Cout << array[start] << endl;
}
}
(Multiple Choice)
4.8/5
(37)
The factorial of an integer is the product of that integer multiplied by all the positive non-zero integers less than that integer. So, 5! ! is the mathematical symbol for factorial) is 5 * 4 * 3*2*1. 4! is 4*3*2*1, so 5! could be written as 5*4!. So a recursive definition of factorial is n! is n*n-1)!, as long as n >1. 1! is 1. What is the recursive call for this function fact)?
(Multiple Choice)
4.9/5
(38)
What is the output of the following code fragment?
Int f1int n, int m)
{
Ifn < m)
Return 0;
Else ifn==m)
Return m+ f1n-1,m);
Else
Return n+ f1n-2,m-1);
}
Int main)
{
Cout << f15,4);
Return 0;
}
(Multiple Choice)
4.8/5
(39)
If the recursive function call does not lead towards a stopping case, you have ______________.
(Short Answer)
4.8/5
(34)
Showing 1 - 20 of 48
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)