Answered step by step
Verified Expert Solution
Question
00
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 sum while i nn: sum i i i sum while i nn: sum i ii k n n k if n : k n else: for i in rangen: for j in rangen: iii for i in rangen: for j in rangei n: if j i: for k in rangen: sum iv for i in rangen: for j in rangei n: if j i: for k in rangen: sum What is the asymptotic complexity of the following functions? Justify your answer. i def funn: sum ; if n : return else: sum sum funn for i in rangen: printend sum i return sum Recurrence Relation: Complexity in BigOh: ii def funa b: if b : return if b : return funaa b elif: return funa ba Recurrence Relation: Complexity in BigOh: iii Assume combineAll is On where n is rightleft def funa left, right: if left right: if aleft: return aleft else: return center intleft right caseLeft funa left, center caseRight funa center right caseLR funaleftcentercenterright combineAllcaseLeft caseRight, caseLR # Assume it is On Recurrence Relation: Complexity in BigOh:
For the following program fragments, give an analysis of the running time using
i
i
sum
while i nn:
sum
i
i
i
sum
while i nn:
sum
i
ii
k
n n k
if n :
k n
else:
for i in rangen:
for j in rangen:
iii
for i in rangen:
for j in rangei n:
if j i:
for k in rangen:
sum
iv
for i in rangen:
for j in rangei n:
if j i:
for k in rangen:
sum
What is the asymptotic complexity of the following functions? Justify your answer.
i
def funn:
sum ;
if n :
return
else:
sum sum funn
for i in rangen:
printend
sum i
return sum
Recurrence Relation:
Complexity in BigOh:
ii
def funa b:
if b :
return
if b :
return funaa b
elif:
return funa ba
Recurrence Relation:
Complexity in BigOh:
iii Assume combineAll is On where n is rightleft
def funa left, right:
if left right:
if aleft:
return aleft
else:
return
center intleft right
caseLeft funa left, center
caseRight funa center right
caseLR funaleftcentercenterright
combineAllcaseLeft caseRight, caseLR # Assume it is On
Recurrence Relation:
Complexity in BigOh:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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