Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In [9]: # Example 1. As an input, a list of numbers of the length N, sorted # in the ascending order, is given. It
In [9]: # Example 1. As an input, a list of numbers of the length N, sorted # in the ascending order, is given. It is known that they # form an arithmetic sequence. write a function to compute # the sum of the numbers in a list. In [5]: def sum(numbers): if numbers == [] or len(numbers) == 0: return 0 else: return (numbers[0] + numbers[-1])*len( numbers)/2 In [7]: # Task la. show that the complexity of the algorithm implemented in Example i # is 0(1). In [8]: # Task 1b. write and test a function to compute a similar sum but for numbers # one knows to form a geometric series. In [ ]: # Task 1c. How the complexity will change if it is necessary to check # whether the numbers in the list reatty form an arithmetic sequence? # (Please write an appropriate code for that check.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started