1 / 17

Analysis of Algorithms

[ Section 4.1 ]. Analysis of Algorithms. Examples of functions important in CS: the constant function: f(n) =. [ Section 4.1 ]. Analysis of Algorithms. Examples of functions important in CS: the constant function: f(n) = c the logarithm function: f(n) = log b n. [ Section 4.1 ].

amish
Télécharger la présentation

Analysis of Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. [ Section 4.1 ] Analysis of Algorithms • Examples of functions important in CS: • the constant function: f(n) =

  2. [ Section 4.1 ] Analysis of Algorithms • Examples of functions important in CS: • the constant function: f(n) = c • the logarithm function: f(n) = logb n

  3. [ Section 4.1 ] Analysis of Algorithms • Examples of functions important in CS: • the constant function: f(n) = c • the logarithm function: f(n) = logb n • the linear function: f(n) =

  4. [ Section 4.1 ] Analysis of Algorithms • 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

  5. [ Section 4.1 ] Analysis of Algorithms • 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

  6. [ Section 4.1 ] Analysis of Algorithms • 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) =

  7. [ Section 4.1 ] Analysis of Algorithms • 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) =

  8. [ Section 4.1 ] Analysis of Algorithms • 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

  9. [ Section 4.2 ] Analysis of Algorithms • How to analyze algorithms • Experimental studies

  10. [ Section 4.2 ] Analysis of Algorithms • 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

  11. [ Section 4.2.3 ] Analysis of Algorithms 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).

  12. [ Section 4.2.3 ] Analysis of Algorithms Examples: f(n) = 5n-3 g(n) = n

  13. [ Section 4.2.3 ] Analysis of Algorithms Examples: f(n) = 7n2+(n3)/5 g(n) = n4

  14. [ Section 4.2.3 ] Analysis of Algorithms Examples: Insert-sort algorithm // input: array A, output: array A is sorted int 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--; } }

  15. [ Section 4.2.3 ] Analysis of Algorithms 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

  16. [ Section 4.2.3 ] Analysis of Algorithms 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)).

  17. [ Section 4.2.5 ] Analysis of Algorithms • Words of caution: • what is 10100n ? • exponential algorithms are a big NO (unless the input is really small)

More Related