1 / 15

CS 336 Feb 13, 2012

CS 336 Feb 13, 2012. Prof. Tandy Warnow. Today’s topics. Review of exam Proofs by contradiction Big-oh. Proof by contradiction. How do we prove that the square root of 2 is irrational? Technique: assume it is rational (the ratio of two integers) and derive a contradiction.

analu
Télécharger la présentation

CS 336 Feb 13, 2012

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. CS 336Feb 13, 2012 Prof. Tandy Warnow

  2. Today’s topics • Review of exam • Proofs by contradiction • Big-oh

  3. Proof by contradiction • How do we prove that the square root of 2 is irrational? • Technique: assume it is rational (the ratio of two integers) and derive a contradiction.

  4. Proof that square root of 2 is irrational • Suppose √2 = p/q for integers p and q that are relatively prime to each other (in particular, not both even) • Then 2 = p2/q2 • And therefore 2q2 = p2 • The left-hand side is even, and therefore the right hand side is even. • Therefore p is even. • Therefore 2q2 is divisible by 4. • Therefore q2 is divisible by 2 • Therefore q is even. • Contradiction!

  5. Proof that there are an infinite number of primes • Suppose there is only a finite number of primes. We list them p1, p2, p3, …, pk. • Now let X = p1 p2 p3 … pk +1 • Can X be a prime? • What prime can divide X? • Contradiction!

  6. Big-Oh • A function f(n) is Big-Oh of g(n) if and only if there exists constants C and C’ such that for all n>C, f(n) ≤ C’g(n). • This is written as f(n) is O(g(n)) • Don’t write f(n) = O(g(n)) (it isn’t equality!)

  7. Proving that a function is big-oh of another • You need to find the constants C and C’, and prove the statement holds. • Example: what constants do you need for • f(n)=3n2 and g(n)=n2+5? • f(n)=3n2 and g(n)=n2-5? • f(n)=3n2 and g(n)=n3-5?

  8. Techniques for guessing • If f(n) and g(n) are both polynomials then just look at the degree. • If they have the same degree, then both are big-oh of each other. • If degree(f) < degree(g) then f(n) is big-oh of g(n), but not vice-versa • Example: • f(n)=3n2 and g(n)=n3+2n+5? • f(n)=3n2 and g(n)=n2+5n3+5? • f(n)=3n2 and g(n)=n+5?

  9. Other techniques • Logarithms grow more slowly than polynomials • Polynomials grow more slow than exponentials • Examples • F(n)= 3 log n, G(n) = n+5 • F(n) = 3 log5 n, G(n) = n-100 • F(n) = 3 log10n, G(n) = √n • F(n) = 5n100, G(n) = 3n

  10. An equivalent definition • f(n) is O(g(n)) if and only if there are constants C and C’ s.t. f(n) ≤ C’g(n) when n>C. • Therefore f(n) is O(g(n)) if and only if there is a constant C’ s.t. limn∞ f(n)/g(n) ≤ C’

  11. Other techniques • L’Hôpital’s rule • Assuming f(n) and g(n) are both differentiable: limn∞ f(n)/g(n) = limn∞f’(n)/g’(n) • Therefore, we can test if f(n) is big-oh of g(n) by seeing if limn∞ f’(n)/g’(n) ≤ C’

  12. Using L’Hôpital’s rule • limn f(n)/g(n) = limn f’(n)/g’(n) • Suppose f(n)=5n and g(n)=2n2-1000 limn f(n)/g(n) = limn f’(n)/g’(n) = limn 5/(4n) = 0 < 1 Therefore f(n) is O(g(n)) (we set C’=1)

  13. Using L’Hôpital’s rule • limn f(n)/g(n) = limn f’(n)/g’(n) • Suppose f(n)=5n and g(n)=ln n limn f(n)/g(n) = limn f’(n)/g’(n) = limn 5/(1/n) = 5n =  Therefore f(n) is NOT O(g(n))

  14. Using L’Hôpital’s rule • limn f(n)/g(n) = limn f’(n)/g’(n) • Suppose f(n)=5n and g(n)= 10n-200 limn f(n)/g(n) = limn f’(n)/g’(n) = limn 5/10 = 1/2 Therefore f(n) is O(g(n)) (we set C’=1)

  15. Using L’Hôpital’s rule • limn f(n)/g(n) = limn f’(n)/g’(n) • Technique to determine if f(n) is O(g(n)) • Compute the limit of f(n)/g(n) • If this is any constant, then f(n) is O(g(n)) • If this is infinity, then f(n) is not O(g(n))

More Related