Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the following program fragments, give an analysis of the running time ( using ) i ) i = 1 sum = 0 while i

For the following program fragments, give an analysis of the running time (using )
i)
i =1
sum =0
while i < n*n:
sum+=1
i +=3
i)
i =1
sum =0
while i < n*n:
sum+=1
i *=3
ii)
k =1
n = n * k
if n <10:
k = n
else:
for i in range(n):
for j in range(n):
iii)
for i in range(n):
for j in range(i*2, n**3):
if j > i:
for k in range(n**2):
sum+=1
iv)
for i in range(n):
for j in range(i*2, n**3):
if j < i:
for k in range(n**2):
sum+=1
What is the asymptotic complexity of the following functions? Justify your answer.
i)
def fun1(n):
sum =0;
if (n <1):
return 1
else:
sum = sum + fun1(n -1)
for i in range(n//2):
print("*",end="")
sum += i
return sum
Recurrence Relation:
Complexity in Big-Oh:
ii)
def fun2(a, b):
if (b ==0):
return 1
if (b %3==0):
return fun2(a*a, b//3)
elif:
return fun2(a, b//3)*a
Recurrence Relation:
Complexity in Big-Oh:
iii) Assume combineAll() is O(n) where n is right-left.
def fun3(a, left, right):
if left == right:
if a[left]>0:
return a[left]
else:
return 0
center = int((left + right)/2)
caseLeft = fun3(a, left, center)
caseRight = fun3(a, center+1, right)
caseLR = fun3(a,(left+center)//2,(center+right)//2)
combineAll(caseLeft, caseRight, caseLR) # Assume it is O(n)
Recurrence Relation:
Complexity in Big-Oh:

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Enhance the basic quality of your voice.

Answered: 1 week ago

Question

Describe the features of and process used by a writing team.

Answered: 1 week ago