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
Given the following recursive function definition, what is the stopping case?
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.9/5
(36)
In the binary search program, each time through the list, we cut the list approximately
(Multiple Choice)
4.8/5
(41)
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
(39)
For every recursive solution, there is an) ______________ solution.
(Short Answer)
4.8/5
(36)
Implementing a task recursively rather than iteratively generally
(Multiple Choice)
4.8/5
(33)
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+2, limit);
}
int main)
{
cout << f12,4)<<endl;
return 0;
}
(Short Answer)
4.7/5
(32)
The square of n can be calculated by noting that squaren) = squaren-1) + diffn-1). diffn) = diffn-1)+2. The square0)=0, diff0)=1. What is the stopping condition for this recursive definition?
(Multiple Choice)
4.8/5
(31)
There can be more than one stopping case in a recursive function.
(True/False)
4.8/5
(35)
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
(36)
In a recursive power function that calculates some base to a positive exp power, at what value of exp do you stop? The function will continually multiply the base times the value returned by the power function with the base argument one smaller.
(Short Answer)
4.8/5
(41)
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.9/5
(35)
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 << f11,2)<<endl;
Return 0;
}
(Multiple Choice)
5.0/5
(44)
Given the following code fragment, what is the stopping conditions)?
int f1int x, int y)
{
ifx<0 || y<0)
return x-y;
else
return f1x-1,y) + f1x,y-1);
}
int main)
{
cout << f11,2)<<endl;
return 0;
}
(Short Answer)
4.9/5
(37)
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 << f112,4)<<endl;
Return 0;
}
(Multiple Choice)
4.9/5
(30)
Showing 21 - 40 of 48
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)