Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 5 : View the code in the cell below, then answer the questions in the cells that follow. In [ ] : def example

Problem 5: View the code in the cell below, then answer the questions in the cells that follow.
In []: def example1(S): # from textbook, section 3.5, page 143
"'"" Return the sum of the elements in sequence S.""1"
n=len(S)
total =0
for j in range (n) :
total +=S[j]
return total
P5, 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.
Put your response in the next cell.
In []:
P5, Q2: What is the big-Oh family for the above code? Enter the response in the next cell.
In []:
image text in transcribed

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

Students also viewed these Databases questions

Question

2. How much time should be allocated to the focus group?

Answered: 1 week ago