Question: def example1(S): # from textbook, section 3.5, page 143 Return the sum of the elements in sequence S. n = len(S) total =

def example1(S): # from textbook, section 3.5, page 143 """ Return the sum of the elements in sequence S. """ n = len(S) total = 0 for j in range (n): total += S[j] return total

Q1: What is the T(n) for the above code based on a static analysis? You may use the symbol 'c' for anything that's constant rather than trying to estimate the number of operations. For example, T(n) = cn^2 + cn + c is a valid function (n^2 is "n-squared"). We can do that because our analysis showed that the constant factors are not crucial when measuring the growth rate. Then, the big-Oh family of this particular function, T(n), is O(n^2) based on the cn^2 factor

Q2: What is the big-Oh family for the above code? Enter the response in the next cell.

                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!