Question: QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0) return 0; else return n * f(n -

QUESTION 1

For the following recursive function, find f(5):

int f(int n) { if (n == 0) return 0; else return n * f(n - 1); }

A.

120

B.

60

C.

1

D.

0

10 points

QUESTION 2

Which of the following statements could describe the general (recursive) case of a recursive algorithm?

In the following recursive function, which line(s) represent the general (recursive) case?

void PrintIt(int n ) // line 1

{ // line 2

if (n > 0) //line 3

{ //line4

cout << "Again" << endl; //line 5

PrintIt(n - 1); // line 6

} // line 7

else // line 8

cout << n << endl; // line 9

} // line 10

A.

Lines 5 6

B.

Lines 5 9

C.

Lines 6 9

D.

Line

E.

None of the above.

10 points

QUESTION 3

Recursion is memory-intensive because:

A.

Recursive functions tend to declare many local variables.

B.

Many copies of the function code are created

C.

Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack.

D.

It requires large data values

E.

None of these answers are correct.

10 points

QUESTION 4

Recursion uses more memory space than iteration because

A.

it uses stack instead of queue.

B.

every recursive call has to be stored.

C.

both A & B are true.

D.

None of the above are true.

10 points

QUESTION 5

Read the following code and determine what goes in blank #1.

int Length(NodeType* list)

// Pre: list has been initialized.

// Post: Length returns the number of elements in list. No counter is kept as

// part of the list. This function is recursive.

{

if (______________) // 1

_______________; // 2

else _______ // 3

}

A.

list == NULL

B.

list->info = 0

C.

list->next == NULL

D.

list != NULL

E.

None of these answers is correct.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!