Algo Analyzing Algorithms
Algo Analyzing Algorithms
Assume: ,
is
is
is
is
is
3 0
Asym
ptotic
FARIHA TABASSUM ISLAM, LECTURER, DEPT. OF CSE, UIU 12
EXACT COST ANALYSIS: EXAMPLE 2
Observe Line 1
value of : , … until less than 0
therefore, runs times
Observe Line 4
value of :
value of :
Best case:
Worst case: or
3 0
Asym
ptotic
FARIHA TABASSUM ISLAM, LECTURER, DEPT. OF CSE, UIU 18
EXACT COST ANALYSIS: EXAMPLE 3
Observe Line 4
value of :
Best case:
Worst case: or
Asym
ptotic
Derive the running-time equations and
express in "O" notation
Asym
ptotic
Derive the running-time equations and
express in "O" notation
Total
cost =
=
Total
cost of =
Line 3 =
The running time of this algorithm therefore belongs to both and , which means it is in
FARIHA TABASSUM ISLAM, LECTURER, DEPT. OF CSE, UIU 28
EXACT COST ANALYSIS: EXAMPLE 5
Line Worst Best
Total
cost =
=
=
Total
cost =
=
Asym
PRACTICE
Derive the best and worst case running-time equations and express in O
notation.
Derive the exact cost equation and express in O notation
Provide best and worst case examples
https://www.geeksforgeeks.org/practice-questions-time-com
plexity-analysis/
https://www.geeksforgeeks.org/practice-questions-time-com
plexity-analysis/
https://www.cs.auckland.ac.nz/courses/compsci220s1t/lectures/lecturenotes/GG-l
ectures/BigOhexamples.pdf
http://www.cs.utsa.edu/~bylander/cs3233/big-oh.pdf
https://youtu.be/FEnwM-iDb2g
https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-
faster-than-processing-an-unsorted-array/11227902#11227902