Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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+

image text in transcribed

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

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

A site - to - site VPN uses routers on the edge of each site.

Answered: 1 week ago

Question

What coaching do you currently provide for your leaders?

Answered: 1 week ago

Question

How consistent is the approach to coaching across the company?

Answered: 1 week ago

Question

How committed are you to this action on a scale of 110?

Answered: 1 week ago