Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago