Upload
justin-lester
View
213
Download
0
Embed Size (px)
Citation preview
Algorithms analysis and design
BYLecturer: Aisha Dawood
2
stands alone on the right-hand side of an equation (or inequality), example : n = O(n2). means set membership :n O(n∈ 2).
when it appears in a formula, we interpret it as standing for some function that we do not care to name. For example, 2n2 + 3n + 1 = 2n2 + (n).
Left hand side and right hand side example : 2n2 + (n) = O(n2).
Order of growth notations in equations and inequalities
3
the relational properties of real numbers apply to asymptotic comparisons as well.
Comparing functions
4
5
For any two functions f(n) and g(n), we have f(n) = (g(n)), if and only if f(n) = O(g(n)) and f(n) = Ω(g(n)).
Proof: left as a home work….
Theorem
6
Common expressions used to describe algorithm’s running time:
Name Expression
Constant 1 ,2,…,c
Logarithmic log(n)
Log squared log2(n)
Linear n
n log n n.log(n)
Quadratic n2
Cubic n3
Exponential 2n
7
Conclusions (f(n)) describes f(n) f(n) = O(g(n)) and f(n) = Ω(g(n)). o(f(n) describes f(n) f(n) = O(g(n)) but not f(n) = Ω(g(n)). ω(f(n)) describes f(n) f(n) = Ω(g(n)) but not f(n) = O(g(n)).
8
Rule #1: Sequential composition: Worst case running time of a sequence :
Rules For Big Oh Analysis of Running Time
9
Rule #2: Iteration: Worst case running time of an iteration:
Rules For Big Oh Analysis of Running Time
For (S1)S2S3...SmO(T(n)) = MAX (O(T1(n)),O(T2(n)),...,O(Tm(n)))
10
Rule #3: Conditional execution: Worst case running time of a conditional
statement :
Rules For Big Oh Analysis of Running Time
11
Determine a tight big-oh bound on the running time of a program to compute the series of sums S0 , S1, S2..., Sn-1 where
T(n) = O(n2)
Example-Prefix Sums
12
The Fibonacci numbers are the series of numbers F0,F1 ,F2 ... given by
Consider the sequence of Fibonacci numbers
T(n) = O(n)
Example-Fibonacci Numbers
13
we use the definition of Fibonacci numbers to implement directly a recursive algorithm
Example-Fibonacci Numbers
14
T(n) = Ω(Fn+1) By induction from the nature of the problem we get T(n) = Ω(2n)
Example-Fibonacci Numbers