1 / 47

Algorithm Design and Analysis (ADA)

Algorithm Design and Analysis (ADA). 242-535 , Semester 1 2013-2014. Objective to introduce mathematical induction through examples . 1. M athematical Induction. Overview. 1 . Motivation 2 . Induction Defined 3 . Maths Notation Reminder 4 . Four Examples

etan
Télécharger la présentation

Algorithm Design and Analysis (ADA)

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. Algorithm Design and Analysis (ADA) 242-535, Semester 1 2013-2014 • Objective • to introduce mathematical induction through examples 1. Mathematical Induction

  2. Overview 1. Motivation 2. Induction Defined 3. Maths Notation Reminder 4. Four Examples 5. More General Induction Proofs 6. A Fun Tiling Problem

  3. 1. Motivation • Induction is used in mathematical proofs of many recursive algorithms • e.g. quicksort, binary search • Induction is used to mathematically define recursive data structures • e.g. lists, trees, graphs continued

  4. Induction is often used to derive mathematical estimates of program running time • timings based on the size of input data • e.g. time increases linearly with the number of data items processed • timings based on the number of times a loop executes

  5. 2. Induction Defined • Induction is used to solve problems such as: • is S(n) correct/true for all n values? • usually for all n >= 0 or all n >=1 • Example: • let S(n) be "n2 + 1 > 0" • is S(n) true for all n >= 1? S(n) can be much more complicated, such as a program that reads in ann value. continued

  6. How do we prove (disprove) S(n)? • One approach is to try every value of n: • is S(1) true? • is S(2) true? • ... • is S(10,000) true? • ... forever!!! Not very practical

  7. Induction to the Rescue • Induction is a technique for quickly proving S(n) true or false for all n • we only have to do two things • First show that S(1) is true • do that by calculation as before continued

  8. " stands for "implies" • We prove that S(n) S(n+1)is true • Read as "if S(n) is true then S(n+1) is true" • When S(1) is true and "S(n)  S(n+1)" is true, then S(n) is true for all n>=1. • Why? continued

  9. With S(1) and S(n)  S(n+1)then S(2) is true • S(1)  S(2) when n == 1 • With S(2) and S(n)  S(n+1)then S(3) is true • S(2)  S(3) when n == 2 • With S(3) and S(n)  S(n+1)then S(4) is true • S(3)  S(4) when n == 3 • and so on, for all n

  10. Proving S(n)  S(n+1) • We prove the implication by: • 1. Assume that S(n) is true; write it down • 2. Write down some extra maths, which depends on the problem • e.g. (n+1)! = n! * (n+1) • 3. Write down S(n+1) • 4. Combine S(n) and the maths to obtain S(n+1)

  11. Let’s do it • Prove S(n): "n2 + 1 > 0" for all n >= 1. • First task: show S(1) is true by calculation • S(1) == 12+ 1 == 2, which is > 0 • so S(1) is true • Second task: prove S(n)  S(n+1) is true continued

  12. Assume S(n) is true • S(n): n2 + 1 > 0 • Extra maths: n > 0 • Write down S(n+1) • S(n+1) == (n+1)2 + 1 == n2 + 2n + 1 +1 == (n2 + 1) + 2n + 1 continued

  13. Use S(n) and the extra maths to show that S(n+1) is true • S(n) means that n2 + 1 > 0, and the extra maths is n > 0,so (n2 + 1) + 2n + 1 > 0 • this means that S(n+1) is true • so S(n)  S(n+1) continued

  14. We have used induction to show two things: • S(1) is true • S(n)  S(n+1) is true • From these it follows that S(n) is true for all n >= 1

  15. Induction More Formally • Three pieces: • 1. A statement S(n) to be proved • the statement must be about an integer n • 2. A basis for the proof. This is the statement S(b) for some integer. Often b = 0 or b = 1. continued

  16. 3. Aninductive step for the proof. We prove the statement “S(n)  S(n+1)” • The statement S(n), used in this proof, is called the inductive hypothesis • We conclude that S(n) is true for all n >= b • S(n) might not be true for some n < b

  17. 3. Maths Notation Reminder • Summation: means 1+2+3+4+…+n • e.g. means 4+9+16+…+m2 • Product: means 1*2*3*…*n

  18. 4. Example 1 • Prove the statement S(n):for all n >= 1 • e.g. 1+2+3+4 = (4*5)/2 = 10 • Basis. S(1), n = 1so 1 = (1*2)/2 continued

  19. Inductive Step. Prove S(n)  S(n+1) • 1. Assume S(n) is true: • 2. The extra maths involve summations: • 3. We want to calculate S(n+1): (1) (2) (3) continued

  20. To prove S(n)  S(n+1), combine S(n) (equation 1) and the extra maths (equation 2) to calculate S(n+1) (equation 3). continued

  21. Substitute the right hand side (rhs) of (1) for the first operand of (2), to give: = (n2 + n + 2n + 2) /2 = (n2+3n+2)/2 which is (3) continued

  22. We have shown: • S(1) is true • S(n)  S(n+1) is true • This means that S(n) is true for all n ≥ 1 • Finished. continued

  23. Example 2 • Prove the statement S(n):for all n >= 0 • e.g. 1+2+4+8 = 16-1 • Basis. S(0), n = 0so 20 = 21 -1 continued

  24. Inductive Step. Prove S(n)  S(n+1) • 1. Assume S(n) is true: • 2. The extra maths involve summations: • 3. We want to calculate S(n+1): (1) (2) (3) continued

  25. To prove S(n)  S(n+1), combine S(n) (equation 1) and the extra maths (equation 2) to calculate S(n+1) (equation 3). continued

  26. Substitute the right hand side (rhs) of (1) for the first operand of (2), to give: = 2*(2n+1) - 1 which is (3)

  27. We have shown: • S(0) is true • S(n)  S(n+1) is true • This means that S(n) is true for all n ≥ 0 • Finished. continued

  28. Example 3 • Prove the statement S(n): n! >= 2n-1for all n >= 1 • e.g. 5! >= 24, which is 120 >= 16 • Basis. S(1), n = 1: 1! >= 20so 1 >= 1 continued

  29. Inductive Step. Prove S(n)  S(n+1) • 1. Assume S(n) is true: n! >= 2n-1 • 2. The extra maths involve factorials:(n+1)! = n! * (n+1) • 3. We want to calculate S(n+1):(n+1)! >= 2(n+1)-1>=2n (1) (2) (3) continued

  30. To prove S(n)  S(n+1), combine S(n) (equation 1) and the extra maths (equation 2) to calculate S(n+1) (equation 3). continued

  31. Substitute the right hand side (rhs) of (1) for the first operand of (2), to give: (n+1)! >= 2n-1 * (n+1)>= 2n-1 * 2since (n+1) >= 2 (n+1)! >= 2n which is (3) why?

  32. We have shown: • S(1) is true • S(n)  S(n+1) is true • This means that S(n) is true for all n ≥ 1 • Finished. continued

  33. Example 4 • Prove the statement S(n):for all n >= 1 • This proof can be used to show that. the limit of the sum:is 1 • Basis. S(1), n = 1so 1/2 = 1/2 continued

  34. Inductive Step. Prove S(n)  S(n+1) • 1. Assume S(n) is true: • 2. The extra maths involve summations: • 3. We want to calculate S(n+1): (1) (2) (3) continued

  35. To prove S(n)  S(n+1), combine S(n) (equation 1) and the extra maths (equation 2) to calculate S(n+1) (equation 3). continued

  36. Substitute the right hand side (rhs) of (1) for the first operand of (2), to give: = which is (3)

  37. We have shown: • S(1) is true • S(n)  S(n+1) is true • This means that S(n) is true for all n ≥ 1 • Finished. continued

  38. 5. More General Inductive Proofs • There can be more than one basis case. • We can usestronginduction where the proof of S(n+1) may use any of S(b), S(b+1), …, S(n) • b is the lowest basis value

  39. Strong Induction Example • Show: • S(1) is true • S(2) is true • S(3) is true • S(n-2)  S(n+1) is true • This means that S(n) is true for all n ≥ 1 • Why? 3 base cases

  40. Example • Every integer >= 24 can be written as 5a+7b for non-negative integers a and b. • note that some integers < 24 cannot be expressed this way (e.g. 16, 23). • Let S(n) be the statement (for n >= 24) “n = 5a + 7b, for a >= 0 and b >= 0” continued

  41. Using Strong Induction • We will show: • S(24) is true • S(25) is true • S(26) is true • S(27) is true • S(28) is true • S(n-4)  S(n+1) is true • This means that S(n) is true for all n ≥ 24 • Why? 5 base cases

  42. Basis. The 5 basis cases are 24 through 28. • S(24) true because24 = (5*2) + (7*2) • S(25) true because 25 = (5*5) + (7*0) • S(26) true because 26 = (5*1) + (7*3) • S(27) true because 27 = (5*4) + (7*1) • S(28) true because 28 = (5*0) + (7*4) continued

  43. Inductive Step. Prove S(n-4)  S(n+1) • 1. Assume S(n-4) is true: n - 4 = 5a + 7b • 2. No extra maths • 3. We want to calculate S(n+1):n+1 = 5a'+7b' • To prove S(n-4)  S(n+1), use S(n-4) (equation 1) to calculate S(n+1) (equation 2). (1) (2) continued

  44. Use S(n-4): n-4 = 5a + 7b • Add 5 to both sides of the equation: • n-4 + 5 = 5a + 7b + 5 • n + 1 = 5(a + 1) + 7b • n + 1 = 5a' + 7b (a' is some new variable) • which means that S(n+1) is true

  45. We have shown: • S(24), S(25), S(26), S(27), S(28) are true • S(n-4)  S(n+1) is true • This means that S(n) is true for all n ≥ 24 • Finished. continued

  46. 6. A Tiling Problem • A right tromino is a “corner” shapemade of 3 squares: • Use induction to prove that any number of right trominos can be used to tile (cover) any n*n size board of squares • but n must be a power of 2 • e.g. board sizes can be 2*2, 4*4, 8*8, 16*16, ... • Show that a tiled board will always have 1 blank square. continued

  47. For example, a 4*4 board (22*22), with 1 blank square: 5 trominos used

More Related