















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of algorithmic complexity analysis, with a focus on identifying and analyzing critical sections of algorithms. Critical sections are the heart of an algorithm, dominating overall execution time, and are contained inside deeply nested loops or recursion. By understanding the characteristics and executions of critical sections, we can determine the asymptotic complexity of an algorithm. Several examples to illustrate the concepts.
Typology: Study notes
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















Overview
Critical Section of Algorithm
Operation central to functioning of program Contained inside deeply nested loops Executed as often as any other part of algorithm
Loops Recursion
Critical Section Example 1
for (int i = 0; i <
n
; i++)
once
n
times
once
Critical Section Example 3
for (int
i
= 0; i <
n
; i++)
for (int j =
i
+1; j <
n
; j++)
once
n (n-1)
times
2
2
Critical Section Example 4
for (int i = 0; i <
n
; i++)
for (int j = 0; j <
; j++)
once
n
times
Critical Section Example 6
i = 1
while (i <
n
i = 2
i
log(
n
) times
times
Critical Section Example 7
DoWork (int n)
if (n == 1)
else
DoWork(n/2)
DoWork(n/2)
times
DoWork(n/2)
times
Recursive Algorithm Example
DoWork (int n)
if (n == 1)
else
DoWork(n/2)
DoWork(n/2)
Asymptotic Complexity Categories
Constant
Array access
log(n)
Logarithmic
Binary search
n
Linear
Largest element
n log(n)
N log N
Optimal sort
n
2
Quadratic
2D Matrix addition
n
3
Cubic
2D Matrix multiply
n
k
Polynomial
Linear programming
k
n
Exponential
Integer programming
From smallest to largestFor size
n
, constant
k
Complexity Comparison Examples
n
lim
n
→→→→
lim
n
→→→→
lim
n
→→→→
lim
n
→→→→
n
Not clear, use
L’Hopital’s Rule
Additional Complexity Measures
Big-O
Represents upper bound on # steps
Big-Omega
Represents lower bound on # steps
Big-Theta
Represents combined upper/lower bound on # steps Best possible asymptotic solution
Additional Complexity Categories
Nondeterministic polynomial time (NP)
Polynomial space
Exponential space
Decidable
Can be solved by finite algorithm
Undecidable
Not solvable by finite algorithm
Quadratic algorithms usually too slow for large data Use fast
heuristics
to provide non-optimal solutions
NP Time Algorithm
If make correct
guesses
on how to proceed
Boolean satisfiability Traveling salesman problem (TLP) Bin packing
Most efficient trip routes Most efficient schedule for employees Most efficient usage of resources