Professional Documents
Culture Documents
Class 02 (DAA) (4th Sem)
Class 02 (DAA) (4th Sem)
PCC-CS404
Design and Analysis of Algorithms
Asymptotic Notations
Recurrence Relation
Asymptotic Notations
2
Big-O
f n O g n : there exist positive constants c and n 0 such that
0 f n cg n for all n n0
3
Big-O(cont.)
Visualization of O(g(n))
cg(n)
f(n)
n0
4
Big-O(cont.)
Examples:
n2 = O(n2):
5
Example
Prove that 5n+3= O (n)
6
Example
7
Big-O(cont.)
8
Big-O(cont.)
Examples :
• Prove that: 20 n 2 n 5 O n
2 2
• Let c = 21 and n0 = 4
• 21n2 > 20n2 + 2n + 5 for all n > 4
n2 > 2n + 5 for all n > 4
TRUE
9
Big Omega – Notation
• () – A lower bound
f n g n : there exist positive constants c and n 0 such that
0 f n cg n for all n n0
Consider F(n) = n2
– n2 = (n)
– Let c = 1, n0 = 2
– For all n 2, n2 > 1 n
10
Big Omega – Notation(cont.)
Visualization of (g(n))
f(n)
cg(n)
n0
11
Example
12
-Notation
f n g n f n O g n AND f n g n
13
-Notation(cont.)
Visualization of (g(n))
c2g(n)
f(n)
c1g(n)
n0
14
Example
Prove that 5n+3=Ѳ(n)
15
Classifying functions by their
Asymptotic Growth Rates
• O(g(n)), Big-Oh of g of n, the Asymptotic Upper
Bound;
• (g(n)), Theta of g of n, the Asymptotic Tight
Bound; and
• (g(n)), Omega of g of n, the Asymptotic Lower
Bound.
Growth of Functions
17
Recursion
Recursion is a particularly powerful kind of reduction, which can be described loosely as
follows:
• If the given instance of the problem is small or simple enough, just solve it.
• Otherwise, reduce the problem to one or more simpler instances of the same problem.
18
There are various techniques to solve recurrences.
1. Substitution Method
2. Iteration Method
3. Recursion Tree Method
4. Master Method
19
Substitution Method
The Substitution Method Consists of two main steps:
20
Substitution Method
21
Substitution Method
22
END
23