Question: Problem 3 : Below are two functions that calculates the sum of the first n integers using python. In other words, sum ( n )
Problem : Below are two functions that calculates the sum of the first n
integers using python. In other words, sumn n
def sumn:
if n :
return
else:
return n sumn
def sumn:
return nn
Answer the questions below:
a Choose different numbers for n Verify that sumn equals sumn for
these numbers.
b Which of these two functions do you think is generally more efficient for
n Why do you think this is so
c Do you think sum or sum is more efficient? Why?
d What happens if you call sum
e Lets define the open sentance:
Pn: sumn is a valid calculation.
i What is the smallest n in N such that Pn is true? Lets label this
case Pb where b is this smallest such number. In other words,
what is b
ii What is Pb What is Pb What is Pb Are these also
true statements?
iii. Is the following statement true or false: Pb Pb
iv Assume you could use sumn to validate whether sumn is correct
for large number of n How would you rewrite the open statement
Pn
v Can you rewrite sumn so that it calls sumn
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
