Download presentation

Presentation is loading. Please wait.

Published byRachel Christie Modified over 2 years ago

1
Analysis of Algorithms Rate of Growth of functions Prof. Muhammad Saeed

2
Analysis of Algorithms2 Rate of Growth of functionsRate of Growth of functions

3
Analysis of Algorithms3

4
4

5
nn(log(n))n(log(log(n)))n(log^2(n))n(log(n^2))n^1.5n Analysis of Algorithms5

6
Assume N = 100,000 and processor speed is 1,000,000 operations per secondAssume N = 100,000 and processor speed is 1,000,000 operations per second FunctionRunning Time 2N2N over 100 years N3N years N2N2 2.8 hours N*N 1/ seconds N log N1.2 seconds N0.1 seconds N 1/2 3.2 x seconds log N1.2 x seconds Running Times Analysis of Algorithms6

7
7 Series and AsymptoticsSeries and Asymptotics

8
Series I Analysis of Algorithms8

9
Series II

10
Infinite Series Analysis of Algorithms10

11
Fundamental Definitions Asymptotics Fundamental Definitions Asymptotics T(n) = O(f(n)) if there are constants c and n 0 such that T(n) cf(n) when n n 0T(n) = O(f(n)) if there are constants c and n 0 such that T(n) cf(n) when n n 0 T(n) = (g(n)) if there are constants c and n 0 such that T(n) cg(n) when n n 0T(n) = (g(n)) if there are constants c and n 0 such that T(n) cg(n) when n n 0 T(n) = (h(n)) if and only if T(n) = O(h(n)) and T(n) = (h(n))T(n) = (h(n)) if and only if T(n) = O(h(n)) and T(n) = (h(n)) T(n) = o(p(n)) if T(n) = O(p(n)) andT(n) = o(p(n)) if T(n) = O(p(n)) and T(n) (p(n)) Analysis of Algorithms11

12
Analysis of Algorithms12 T(n) = O(f(n)) T(n) = (g(n)) T(n) = (h(n)) Asymptotics

13
Analysis Type Mathematical Expression Relative Rates of Growth Big OT(N) = O( F(N) )T(N) < F(N) Big T(N) = ( F(N) ) T(N) > F(N) Big T(N) = ( F(N) ) T(N) = F(N) Relative Rates of Growth Analysis of Algorithms13

14
Relative Growth Rate of Two Functions Compute using LHopitals Rule Limit=0: f(n)=o(g(n)) Limit=0: f(n)=o(g(n)) Limit=c 0:f(n)= (g(n)) Limit=c 0:f(n)= (g(n)) Limit= :g(n)=o(f(n)) Limit= :g(n)=o(f(n)) Analysis of Algorithms14

15
3n 3 = O(n 3 ) 3n = O(n 3 ) 8n n * log(n) + 100n = O(n 2 ) 3log(n) + 2n 1/2 = O(n 1/2 ) = O(1) T linearSearch (n) = O(n) T binarySearch (n) = O(log(n)) Important Rules Analysis of Algorithms15

16
Important Rules Rule 1: If T 1 (n) = O(f(n)) and T 2 (n) = O(g(n)), then a) T 1 (n) + T 2 (n) = max(O(f(n)), O(g(n))) a) T 1 (n) + T 2 (n) = max(O(f(n)), O(g(n))) b) T 1 (n) * T 2 (n) = O(f(n)*g(n)) Rule 2: If T(x) is a polynomial of degree n, then T(x)= (x n ) Rule 3: log k n = O(n) for any constant k. Analysis of Algorithms16

17
General Rules for LoopsLoops Nested LoopsNested Loops Consecutive statementsConsecutive statements if-then-elseif-then-else RecursionRecursion Analysis of Algorithms17

18
Analysis of Algorithms18 Maximum Subsequence SumMaximum Subsequence Sum A case A case

19
int MaxSubsequenceSum( const int A[], const unsigned int N) { int Sum=0, MaxSum=0; for( i = 0; i

20
Maximum Subsequence Sum Algorithm 2 int MaxSubsequenceSum( const int A[], const unsigned int N) { int Sum=0, MaxSum=0; for( i = 0; i

21
Maximum Subsequence Sum Algorithm 3 int MaxSubsequenceSum( const int A[], const unsigned int N) { int Sum = 0, MaxSum = 0, Start = 0, End = 0; for( End = 0; End

22
END Analysis of Algorithms22

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google