1 / 317

Relevant Mathematics

Thinking about Algorithms Abstractly. Relevant Mathematics. Classifying Functions The Time Complexity of an Algorithm Adding Made Easy Recurrence Relations. Lecture 2. Classifying Functions. Time Complexity. t(n) = Q (n 2 ). f(i) = n Q (n). Time. Input Size. Recurrence Relations.

Télécharger la présentation

Relevant Mathematics

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. Thinking about Algorithms Abstractly Relevant Mathematics Classifying Functions The Time Complexity of an Algorithm Adding Made Easy Recurrence Relations Lecture2

  2. 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

  3. Assumed Knowledge Read the section on • Existential and Universal Quantifiers, • Logarithms and Exponentials g "b Loves(b,g)"b g Loves(b,g)

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

  5. Which are more alike?

  6. Which are more alike? Mammals

  7. Which are more alike?

  8. Which are more alike? Dogs

  9. Classifying Animals Vertebrates Fish Reptiles Mammals Birds Dogs Giraffe

  10. 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.

  11. Which are more alike? n1000 n2 2n

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

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

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

  15. Classifying Functions? Functions

  16. 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

  17. Classifying Functions? Polynomial

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

  19. 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.

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

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

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

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

  24. 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 << << << << << <<

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

  26. 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

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

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

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

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

  31. 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).

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

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

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

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

  36. 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)

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

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

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

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

  41. 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

  42. 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)

  43. 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)

  44. Notations

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

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

  47. 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)

  48. Definition of Theta f(n) = θ(g(n)) For all sufficiently large n

  49. Definition of Theta f(n) = θ(g(n)) For all sufficiently large n For some definition of “sufficiently large”

  50. Definition of Theta 3n2 + 7n + 8 = θ(n2)

More Related