








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, focusing on recurrence relations and complexity categories. It covers the definition and components of recursive algorithms, the concept of base and recursive cases, and the use of recurrence relations to analyze the complexity of algorithms. The document also includes examples of recurrence relations and their solutions, as well as a discussion on comparing complexity and calculating asymptotic complexity.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Critical Section Example 7
A ⇒ 1 times DoWork(n/2) ⇒ 2 times
Recursive Algorithms
An algorithm that calls itself
Recurrence Relations
Value of function at some specified points Also called boundary values / boundary conditions
T(2) = k
Solving Recurrence Equations
Iteratively substitute recurrence into formula
T(n) = T(n-1) + 1 = ( T(n-2) + 1 ) + 1 = ( ( T(n-3) + 1 ) + 1 ) + 1 = ( ( ( T(n-4) + 1 ) + 1 ) + 1 ) + 1 = … = (…( T(1) + 1 ) + … ) + 1 = (…( 5 + 1 ) + … ) + 1 = n + 4
Example Recurrence Solutions
T(n) = T(n-1) + k ⇒ O(n) T(n) = T(n-1) + n ⇒ O(n^2 ) T(n) = T(n-1) + T(n-2) ⇒ O(n!) T(n) = T(n/2) + k ⇒ O(log(n)) T(n) = 2 × T(n/2) + k ⇒ O(n) T(n) = 2 × T(n-1) + k ⇒ O(2 n)
Take CMSC 351 – Introduction to Algorithms
Asymptotic Complexity Categories
O(1) Constant Array access O(log(n)) Logarithmic Binary search O(n) Linear Largest element O(n log(n)) N log N Optimal sort O(n^2 ) Quadratic 2D Matrix addition O(n^3 ) Cubic 2D Matrix multiply O(nk) Polynomial Linear programming O(k n^ ) Exponential Integer programming
From smallest to largest
For size n, constant k > 1
Calculating Asymptotic Complexity
Highest complexity term dominates Can ignore lower complexity terms
2 n + 100 ⇒ O(n) n log(n) + 10 n ⇒ O(nlog(n)) ½ n^2 + 100 n ⇒ O(n^2 ) n^3 + 100 n^2 ⇒ O(n^3 ) 1/100 2 n^ + 100 n^4 ⇒ O(2n^ )
Complexity Examples
0
100000
200000
300000
400000
500000
600000
700000
800000
(^1349120260533) (^10682118417582081611131602)
n nlog(n) 2 n + 100
Complexity Examples
0
100000
200000
300000
400000
500000
600000
700000
800000
(^22879178373756) (^150629755855115012256544252)
n nlog(n) 1/2 n log(n) + 10 n
Complexity Examples
0
100000
200000
300000
400000
500000
600000
700000
800000
(^22879) (^178373756150629755855) 115012256544252
nlog(n) n^2 1/2 n^2 + 100 n
Complexity Comparison Examples
lim n→∞
lim n→∞
lim n→∞
lim n→∞
Not clear, use L’Hopital’s Rule
L’Hopital’s Rule
lim n→∞
lim n→∞
=
Using L’Hopital’s Rule
lim n→∞
lim n→∞
lim n→∞
lim n→∞
… ∞
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
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
NP Time Algorithm
Can be solved with exponential time Not proven to require exponential time Currently solve using heuristics
Representative of all NP problems Solution can be used to solve any NP problem Examples Boolean satisfiability Traveling salesman
P = NP?
Prove P=NP Show polynomial time solution exists for any NP-complete problem Prove P≠NP Show no polynomial-time solution possible The expected answer
$1 million prize offered by Clay Math Institute
Algorithmic Complexity Summary
Fundamental measure of efficiency Independent of implementation & computer platform
Examine program Find critical sections Calculate complexity of algorithm Compare complexity