Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Give a big-Oh characterization, in terms of n, of the running time of the example1, example 2 and example 3 functions shown below: Write the
Give a big-Oh characterization, in terms of n, of the running time of the example1, example 2 and example 3 functions shown below:
Write the individual time it takes to execute every statement on every line.
for ex:
1: n=len(S) exectutes in O(1) time.
2: A=[0]*n executes in O(n) time.
3: def example1(S) takes ____ time
4. return total takes ____ time.
5: for j in range(n) takes ___ time.
Do this for all statements of all the functions.
1 def example1(S): 2" Return the sum of the elements in sequence S.""" 3 n=len(s) 4 total = 0 5 for j in range(n) # loop from 0 to n-1 total += S[i] return total 9 def example2(S) 10" Return the sum of the elements with even index in sequence S.""" 11 n=len(S) 12 total = 0 for j in range(0, n, 2) # note the increment of 2 14 15 total +=S[i] return total 17 def example3(S) 18 "Return the sum of the prefix sums of sequence S.""" 19 n=len(S) 20 total 0 21 for j in range(n) 22 for k in range(1+j): 23 24 return total # loop from 0 to n-1 # loop from 0 to j total S[k]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