Exam 14: Recursion

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

A class member function may be recursive.

Free
(True/False)
4.9/5
(43)
Correct Answer:
Verified

True

How do you ensure that your function does not have infinite recursion?

Free
(Essay)
4.9/5
(35)
Correct Answer:
Verified

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:
Verified

recursive calls

If you try to solve a problem recursively, you should

(Multiple Choice)
4.8/5
(34)

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)

Every recursive definition may be rewritten iteratively.

(True/False)
4.8/5
(34)
Showing 1 - 20 of 48
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)