Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

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

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago