Filters
Question type

If the recursive function call does not lead towards a stopping case, you have ______________.

Correct Answer

verifed

verified

infinite r...

View Answer

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; }


A) 0
B) -1
C) 5
D) -5

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

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; }


A) 0
B) 2
C) 4
D) 8
E) infinite recursion

F) C) and E)
G) C) and D)

Correct Answer

verifed

verified

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

Correct Answer

verifed

verified

All recursive calls must lead to a stopping case.

To ensure that your function recurses correctly and the proper result is reached, you must ensure that


A) all stopping cases are correct
B) all recursive calls lead to one of the stopping cases
C) for each case that involves recursion, that case returns the correct value provided all recursive calls in that case return the correct value.
D) all of the above
E) none of the above

F) All of the above
G) None of the above

Correct Answer

verifed

verified

If your program makes too many recursive function calls, your program will cause a ___________


A) stack underflow
B) activation overflow
C) stack overflow
D) syntax error

E) A) and B)
F) None of the above

Correct Answer

verifed

verified

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; }


A) 0
B) 2
C) 4
D) 8
E) infinite recursion

F) C) and D)
G) A) and D)

Correct Answer

verifed

verified

Every time a recursive function call is executed, a new __________ is put on the top of the stack.


A) Activity frame
B) Activity record
C) program
D) Activation frame

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

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; } }


A) infinite recursion
B) the stopping condition is wrong
C) the recursive call is wrong
D) nothing

E) B) and C)
F) A) and B)

Correct Answer

verifed

verified

Recursive functions always execute faster than an iterative function.

A) True
B) False

Correct Answer

verifed

verified

Every recursive definition may be rewritten iteratively.

A) True
B) False

Correct Answer

verifed

verified

In a recursive function, the statements) that invoke the function again are called the ______________.

Correct Answer

verifed

verified

recursive calls

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) ?


A) 8
B) 5
C) 2
D) 1

E) A) and D)
F) None of the above

Correct Answer

verifed

verified

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; } }


A) infinite recursion
B) the stopping condition is wrong
C) the recursive call is wrong
D) nothing

E) B) and C)
F) All of the above

Correct Answer

verifed

verified

If you try to solve a problem recursively, you should


A) find all the stopping cases and the values if needed at that case
B) find a recursive call that will lead towards one of the stopping cases
C) all of the above
D) none of the above

E) B) and C)
F) A) and D)

Correct Answer

verifed

verified

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; }


A) 2
B) 3
C) -1
D) 6

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

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) ; } }


A) 0
B) 1
C) 2
D) 3

E) B) and D)
F) B) and C)

Correct Answer

verifed

verified

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?


A) n<1
B) n==0
C) n==1
D) none of the above

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

A class member function may be recursive.

A) True
B) False

Correct Answer

verifed

verified

True

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) ?


A) factn) *n;
B) factn-1) *n;
C) n-1) *factn)
D) factn-2) *n-1)

E) All of the above
F) B) and D)

Correct Answer

verifed

verified

Showing 1 - 20 of 48

Related Exams

Show Answer