Question: help Problem 4: Below are two functions that calculates the sum of the first n integers using python. In other words, sum(n) = 1+ 2+

help
Problem 4: Below are two functions that calculates the sum of the first n integers using python. In other words, sum(n) = 1+ 2+ 3+ ... + n. == def sumi(n): if (n 1): return 1 else: return n + sumi(n-1) def sum2 (n): return n* (n+1)/2 Answer the questions below: (a) Choose 5 different numbers for n. Verify that suml(n) equals sum2(n) for these 5 numbers. (b) Which of these two functions do you think is generally more efficient for n> 100. Why do you think this is so? (c) Do you think suml(1) or sum2(1) is more efficient? Why? (d) What happens if you call suml(0)? (e) Let's define the open sentance: P(n): suml(n) is a valid calculation. i. What is the smallest n E N such that P(n) is true? Let's label this case P(b), where b is this smallest such number. In other words, what is b? ii. What is P(b+1)? What is P(b+2)? What is P(b+3)? Are these also true statements? iii. Is the following statement true or false: P(b) = P(b+1)? iv. Assume you could use sim2(n) to validate whether siml(n) is correct for large number of n. How would you rewrite the open statement P(n)? v. Can you rewrite siml(n) so that it calls sim2(n)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
