Exam 14: Recursion

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

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)

Only functions that do not return a value may be recursive.

(True/False)
4.8/5
(32)

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)

In order for the binary search to work correctly

(Multiple Choice)
4.7/5
(31)

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)

Recursive functions must return a value.

(True/False)
4.9/5
(36)

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)

Recursive functions may return any type of value

(True/False)
4.8/5
(42)

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)

A recursive function is a function that ______________.

(Short Answer)
4.8/5
(40)

A stack exhibits _________ behavior.

(Multiple Choice)
4.7/5
(42)

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
close modal

Filters

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