Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the asymptotic complexity of the following functions? Justify your answer. i ) def fun 1 ( n ) : sum = 0 ;

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

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions

Question

Networking is a two-way street. Discuss this statement.

Answered: 1 week ago