![Page 1: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/1.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) =
![Page 2: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/2.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) = c
• the logarithm function: f(n) = logb n
![Page 3: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/3.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) = c
• the logarithm function: f(n) = logb n
• the linear function: f(n) =
![Page 4: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/4.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) = c
• the logarithm function: f(n) = logb n
• the linear function: f(n) = n
• the n-log-n function: f(n) = n log n
![Page 5: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/5.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) = c
• the logarithm function: f(n) = logb n
• the linear function: f(n) = n
• the n-log-n function: f(n) = n log n
• the quadratic function: f(n) = n2
![Page 6: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/6.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) = c
• the logarithm function: f(n) = logb n
• the linear function: f(n) = n
• the n-log-n function: f(n) = n log n
• the quadratic function: f(n) = n2
• the cubic function and other polynomials
f(n) = n3
f(n) =
![Page 7: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/7.jpg)
Analysis of Algorithms[ Section 4.1 ]
Examples of functions important in CS:
• the constant function:f(n) = c
• the logarithm function: f(n) = logb n
• the linear function: f(n) = n
• the n-log-n function: f(n) = n log n
• the quadratic function: f(n) = n2
• the cubic function and other polynomials
f(n) = n3
• the exponential function:
f(n) =
![Page 8: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/8.jpg)
Analysis of Algorithms[ Section 4.1 ]
Comparing growth rates
• f(n) = c
• f(n) = logb n
• f(n) = n
• f(n) = n log n
• f(n) = n2
• f(n) = n3
• f(n) = bn
![Page 9: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/9.jpg)
Analysis of Algorithms[ Section 4.2 ]
How to analyze algorithms
- Experimental studies
![Page 10: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/10.jpg)
Analysis of Algorithms[ Section 4.2 ]
How to analyze algorithms
- Counting the number of primitive operations
Note: possible difference between the worst-case running time and the average-case running time
![Page 11: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/11.jpg)
Analysis of Algorithms[ Section 4.2.3 ]
Asymptotic notation
Big-Oh notation:
Let f(n) and g(n) be functions from integers to reals. We say that f(n) = O(g(n)) if there are constants c>0 and n0>0 such that
f(n) · c g(n) for every n ¸ n0
We also say that f(n) is order of g(n).
![Page 12: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/12.jpg)
Analysis of Algorithms[ Section 4.2.3 ]
Examples:
f(n) = 5n-3 g(n) = n
![Page 13: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/13.jpg)
Analysis of Algorithms[ Section 4.2.3 ]
Examples:
f(n) = 7n2+(n3)/5 g(n) = n4
![Page 14: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/14.jpg)
Analysis of Algorithms[ Section 4.2.3 ]
Examples:
Insert-sort algorithm
// input: array A, output: array A is sortedint i,j;int n = A.length;for (i=0; i<n-1; i++) { j = i; while ((j>=0) && (A[j+1]<A[j])) {
int tmp = A[j+1];A[j+1] = A[j];A[j] = tmp;j--;
}}
![Page 15: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/15.jpg)
Analysis of Algorithms[ Section 4.2.3 ]
Asymptotic notation continued
Big-Omega notation:
Let f(n) and g(n) be functions from integers to reals. We say that f(n) = (g(n)) if there are constants c>0 and n0>0 such that
f(n) ¸ c g(n) for every n ¸ n0
![Page 16: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/16.jpg)
Analysis of Algorithms[ Section 4.2.3 ]
Asymptotic notation continued
Big-Theta notation:
Let f(n) and g(n) be functions from integers to reals. We say that f(n) = £(g(n)) if f(n) = O(g(n)) and f(n) = (g(n)).
![Page 17: Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =](https://reader035.vdocuments.us/reader035/viewer/2022070400/56649f135503460f94c2733a/html5/thumbnails/17.jpg)
Analysis of Algorithms[ Section 4.2.5 ]
Words of caution:
• what is 10100n ?
• exponential algorithms are a big NO (unless the input is really small)