Question: 1) Complete the code for the calcPower recursive function shown below, which is intended to raise the base number passed into the function to the

1) Complete the code for the calcPower recursive function shown below, which is intended to raise the base number passed into the function to the exponent power passed into the function:

1. def calcPower(base, exponent): 2. answer = 0 3. if exponent == 0: 4. answer = 1 5. else: 6. _____________________________ 7. return answer 
answer = base * calcPower(base - 1, exponent) 
answer = base * calcPower(base, exponent - 1) 
answer = base * calcPower(base, exponent) 
answer = base * calcPower(base - 1, exponent - 1) 

2) Consider the following recursive code snippet:

1. def mystery(n, m) : 2. if n == 0 : 3. return 0 4. if n == 1: 5. return m 6. return m + mystery(n - 1, m) 

What value is returned from a call to mystery(3,6)

3 
6 
18 
729 

3) Consider the following recursive code snippet:

1. def mystery(n, m): 2. if n <= 0 : 3. return 0 4. if n == 1 : 5. return m 6. return m + mystery(n - 1, m) 

Identify the terminating condition(s) of function mystery?

n <= 0 
n == 1 
n <= 0 or n == 1 
n > 0 

4) Consider the following code snippet for recursive addition:

1. def add(i, j) : 2. # assumes i >= 0 3. if i == 0 : 4. return j 5. else : 6. return add(i - 1, j + 1) 

Identify the terminating condition in this recursive function.

if i == 0 : 
return j 
return add(i - 1, j + 1) 

There is no terminating condition

5) What is required to make a recursive function successful?

I. One or more special cases that handle the simplest computations directly II. A recursive call to a smaller or simpler version of the problem III. Mutually recursive calls

I only
II only
I and II only
I, II, and III

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!