Download
csce 310j data structures algorithms n.
Skip this Video
Loading SlideShow in 5 Seconds..
CSCE 310J: Data Structures & Algorithms PowerPoint Presentation
Download Presentation
CSCE 310J: Data Structures & Algorithms

CSCE 310J: Data Structures & Algorithms

187 Views Download Presentation
Download Presentation

CSCE 310J: Data Structures & Algorithms

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. CSCE 310J: Data Structures & Algorithms Fundamentals of Algorithm Analysis Dr. Steve Goddard goddard@cse.unl.edu http://www.cse.unl.edu/~goddard/Courses/CSCE310J

  2. Most of the slides in this lecture were originally created by Jeff Edmonds from York University

  3. Thinking about Algorithms Abstractly Relevant Mathematics Classifying Functions The Time Complexity of an Algorithm Adding Made Easy Recurrence Relations Jeff Edmonds York University

  4. Classifying Functions Time Complexity t(n) = Q(n2) f(i) = nQ(n) Time Input Size Recurrence Relations Adding Made Easy T(n) = a T(n/b) + f(n) ∑i=1 f(i). Start With Some Math

  5. Assumed Knowledge • Logarithms and Exponentials • Existential and Universal Quantifiers, g "b Loves(b,g)"b g Loves(b,g)

  6. Quantifiers: all, some • “for all x” x P(x) is true iff P(x) is true for all x • universal quantifier (universe of discourse) • “there exist x” x P(x) is true iff P(x) is true for some value of x • existential quantifier • x A(x) is logically equivalent to  x(A(x)) • x A(x) is logically equivalent to x(A(x)) • x (A(x)  B(x)) “For all x such that if A(x) holds then B(x) holds”

  7. Classifying Functions Giving an idea of how fast a function grows without going into too much detail.

  8. Which are more alike?

  9. Which are more alike? Mammals

  10. Which are more alike?

  11. Which are more alike? Dogs

  12. Classifying Animals Vertebrates Fish Reptiles Mammals Birds Dogs Giraffe

  13. T(n) 10 100 1,000 10,000 log n 3 6 9 13 amoeba n1/2 3 10 31 100 bird 10 100 1,000 10,000 human n log n 30 600 9,000 130,000 my father n2 100 10,000 106 108 elephant n3 1,000 106 109 1012 dinosaur 2n 1,024 1030 10300 103000 the universe Classifying Functions n Note: The universe contains approximately 1050 particles.

  14. Which are more alike? n1000 n2 2n

  15. Which are more alike? n1000 n2 2n Polynomials

  16. Which are more alike? 1000n2 3n2 2n3

  17. Which are more alike? 1000n2 3n2 2n3 Quadratic

  18. Classifying Functions? Functions

  19. 25n n5 2 2 Classifying Functions Functions Exp Constant Polynomial Double Exp Exponential Logarithmic Poly Logarithmic 5 5 log n (log n)5 n5 25n

  20. Classifying Functions? Polynomial

  21. Classifying Functions Polynomial ? Cubic Quadratic Linear 5n4 5n3 5n 5n2

  22. Logarithmic • log10n = # digits to write n • log2n = # bits to write n = 3.32 log10n • log(n1000) = 1000 log(n) Differ only by a multiplicative constant.

  23. Poly Logarithmic (log n)5 = log5 n

  24. Logarithmic << Polynomial For sufficiently large n log1000 n << n0.001

  25. Linear << Quadratic For sufficiently large n 10000 n << 0.0001 n2

  26. Polynomial << Exponential For sufficiently large n n1000 << 20.001 n

  27. 25n n5 2 2 Ordering Functions Functions Exp Constant Polynomial << << << << << << Double Exp Exponential Logarithmic Poly Logarithmic 5 5 log n (log n)5 n5 25n << << << << << <<

  28. Yes Yes Yes Yes Yes No Which Functions are Constant? • 5 • 1,000,000,000,000 • 0.0000000000001 • -5 • 0 • 8 + sin(n)

  29. 9 Lie in between 7 Yes Which Functions are “Constant”? The running time of the algorithm is a “Constant” It does not depend significantly on the size of the input. Yes • 5 • 1,000,000,000,000 • 0.0000000000001 • -5 • 0 • 8 + sin(n) Yes Yes No No

  30. Which Functions are Quadratic? • n2 • … ?

  31. Which Functions are Quadratic? • n2 • 0.001 n2 • 1000 n2 Some constant times n2.

  32. Which Functions are Quadratic? • n2 • 0.001 n2 • 1000 n2 • 5n2 + 3n + 2log n

  33. Which Functions are Quadratic? • n2 • 0.001 n2 • 1000 n2 • 5n2 + 3n + 2log n Lie in between

  34. Which Functions are Quadratic? • n2 • 0.001 n2 • 1000 n2 • 5n2 + 3n + 2log n Ignore low-order terms Ignore multiplicative constants. Ignore "small" values of n. Write θ(n2).

  35. Which Functions are Polynomial? • n5 • … ?

  36. Which Functions are Polynomial? • nc • n0.0001 • n10000 n to some constant power.

  37. Which Functions are Polynomial? • nc • n0.0001 • n10000 • 5n2 + 8n + 2log n • 5n2 log n • 5n2.5

  38. Which Functions are Polynomial? • nc • n0.0001 • n10000 • 5n2 + 8n + 2log n • 5n2 log n • 5n2.5 Lie in between

  39. Which Functions are Polynomials? • nc • n0.0001 • n10000 • 5n2 + 8n + 2log n • 5n2 log n • 5n2.5 Ignore low-order terms Ignore power constant. Ignore "small" values of n. Write nθ(1)

  40. Which Functions are Exponential? • 2n • … ?

  41. Which Functions are Exponential? • 2n • 20.0001 n • 210000 n n times some constant power raises to the power of 2.

  42. Which Functions are Exponential? • 2n • 20.0001 n • 210000 n • 8n • 2n / n100 • 2n· n100 too small? too big?

  43. Which Functions are Exponential? • 2n • 20.0001 n • 210000 n • 8n • 2n / n100 • 2n· n100 Lie in between = 23n > 20.5n < 22n

  44. Which Functions are Exponential? • 2n • 20.0001 n • 210000 n • 8n • 2n / n100 • 2n· n100 = 23n > 20.5n < 22n 20.5n > n100 2n = 20.5n· 20.5n > n100· 20.5n 2n / n100 > n0.5n

  45. Which Functions are Exponential? • 2n • 20.0001 n • 210000 n • 8n • 2n / n100 • 2n· n100 Ignore low-order terms Ignore base. Ignore "small" values of n. Ignore polynomial factors. Write 2θ(n)

  46. 2θ(n) nθ(1) 2 2 Classifying Functions Functions Exp Constant Polynomial Double Exp Exponential Logarithmic Poly Logarithmic θ(1) θ(log n) (log n)θ(1) nθ(1) 2θ(n)

  47. Notations

  48. Definition of Theta f(n) = θ(g(n))

  49. Definition of Theta f(n) = θ(g(n)) f(n) is sandwiched between c1g(n)and c2g(n)

  50. Definition of Theta f(n) = θ(g(n)) f(n) is sandwiched between c1g(n)and c2g(n) for some sufficiently small c1 (= 0.0001) for some sufficiently large c2 (= 1000)