poscat seminar 2

84
POSCAT Seminar 2 : Algorithm Verification & Efficiency yougatup @ POSCAT 1

Upload: hyungyu-shin

Post on 21-Jan-2018

60 views

Category:

Education


0 download

TRANSCRIPT

  1. 1. POSCAT Seminar 2 : Algorithm Verification & Efficiency yougatup @ POSCAT 1
  2. 2. Topic Topic today Problem Solving Procedure Algorithm Verification Computational Efficiency Basic arithmetic Multiplication Power Greatest Common Divisor Primarity Testing Nave approach Eratosthenes sieve POSCAT Seminar 1-2 9 July 2014 yougatup Stable Matching Implementation Basic implementation Covering todays topic
  3. 3. Problem Solving Procedure POSCAT Seminar 1-3 9 July 2014 yougatup
  4. 4. Basic Arithmetic Multiplication = 1 + = 1 Verification : Is this algorithm true ? Efficiency : How long does it takes ? POSCAT Seminar 1-4 9 July 2014 yougatup
  5. 5. Basic Arithmetic Multiplication = 1 + = 1 Verification : Is this algorithm true ? POSCAT Seminar 1-5 9 July 2014 yougatup
  6. 6. Basic Arithmetic Multiplication = 1 + = 1 Verification : Is this algorithm true ? POSCAT Seminar 1-6 9 July 2014 yougatup Proof : use Mathematical Induction = + + +
  7. 7. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-7 9 July 2014 yougatup
  8. 8. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-8 9 July 2014 yougatup What is the unit ?
  9. 9. Computational Efficiency , 1 n ? POSCAT Seminar 1-9 9 July 2014 yougatup
  10. 10. Computational Efficiency , 1 n ? n POSCAT Seminar 1-10 9 July 2014 yougatup
  11. 11. Computational Efficiency , 1 n ? O() POSCAT Seminar 1-11 9 July 2014 yougatup
  12. 12. Computational Efficiency Example POSCAT Seminar 1-12 9 July 2014 yougatup
  13. 13. Computational Efficiency Example POSCAT Seminar 1-13 9 July 2014 yougatup O(2 + )
  14. 14. Computational Efficiency Example POSCAT Seminar 1-14 9 July 2014 yougatup O( )
  15. 15. Computational Efficiency Example POSCAT Seminar 1-15 9 July 2014 yougatup
  16. 16. Computational Efficiency Example POSCAT Seminar 1-16 9 July 2014 yougatup O(3 { 1 + 2 + + 1}) swap loop
  17. 17. Computational Efficiency Example POSCAT Seminar 1-17 9 July 2014 yougatup O(3 { (1) 2 })
  18. 18. Computational Efficiency Example POSCAT Seminar 1-18 9 July 2014 yougatup O(3 { 2 2 })
  19. 19. Computational Efficiency Example POSCAT Seminar 1-19 9 July 2014 yougatup O(32)
  20. 20. Computational Efficiency Example POSCAT Seminar 1-20 9 July 2014 yougatup O( )
  21. 21. Computational Efficiency Example POSCAT Seminar 1-21 9 July 2014 yougatup O( )
  22. 22. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-22 9 July 2014 yougatup What is the unit ?
  23. 23. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-23 9 July 2014 yougatup What is the unit ? The number of operations !
  24. 24. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-24 9 July 2014 yougatup So, what is the efficiency ?
  25. 25. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-25 9 July 2014 yougatup So, what is the efficiency ?
  26. 26. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-26 9 July 2014 yougatup So, what is the efficiency ? We need pseudo-code
  27. 27. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-27 9 July 2014 yougatup
  28. 28. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-28 9 July 2014 yougatup O(y)
  29. 29. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-29 9 July 2014 yougatup O(y) Done!
  30. 30. Basic Arithmetic Multiplication = 1 + = 1 Efficiency : How long does it takes ? POSCAT Seminar 1-30 9 July 2014 yougatup O(y) Done! Is there another algorithm faster ?
  31. 31. Basic Arithmetic Multiplication = + (2 2 ) 2 2 Verification : Is this algorithm true ? Efficiency : How long does it takes ? POSCAT Seminar 1-31 9 July 2014 yougatup
  32. 32. Basic Arithmetic Multiplication = + (2 2 ) 2 2 Verification : Is this algorithm true ? Mathematical Induc. Efficiency : How long does it takes ? O(log ) POSCAT Seminar 1-32 9 July 2014 yougatup
  33. 33. Basic Arithmetic Multiplication = + (2 2 ) 2 2 Verification : Is this algorithm true ? Mathematical Induc. Efficiency : How long does it takes ? O(log ) POSCAT Seminar 1-33 9 July 2014 yougatup x*y
  34. 34. Basic Arithmetic Power Derive the efficient algorithm to calculate Find correct algorithm which takes O(log ) Also, give me the pseudo-code POSCAT Seminar 1-34 9 July 2014 yougatup
  35. 35. Basic Arithmetic Euclids Rule gcd , = gcd( , ) Claim. G = gcd , = gcd , Proof. POSCAT Seminar 1-35 9 July 2014 yougatup
  36. 36. Basic Arithmetic Euclids Rule gcd , = gcd( , ) Claim. G = gcd , = gcd , Proof. Any divisor of both x and y also divides x-y Therefore, gcd , is the divisor or gcd( , ) gcd , gcd( , ) POSCAT Seminar 1-36 9 July 2014 yougatup
  37. 37. Basic Arithmetic Euclids Rule gcd , = gcd( , ) Claim. G = gcd , = gcd , Proof. Also, any divisor of both and also divides x Therefore, gcd , gcd( , ) gcd , = gcd( , ) POSCAT Seminar 1-37 9 July 2014 yougatup
  38. 38. Basic Arithmetic Euclids Rule gcd , = gcd( , ) Then G = gcd , = gcd( , ) POSCAT Seminar 1-38 9 July 2014 yougatup
  39. 39. Basic Arithmetic Euclids Rule gcd , = gcd( , ) gcd 248, 32 POSCAT Seminar 1-39 9 July 2014 yougatup
  40. 40. Basic Arithmetic Euclids Rule gcd , = gcd( , ) gcd 248, 32 gcd(24, 32) POSCAT Seminar 1-40 9 July 2014 yougatup
  41. 41. Basic Arithmetic Euclids Rule gcd , = gcd( , ) gcd 248, 32 gcd 24, 32 gcd(32, 24) POSCAT Seminar 1-41 9 July 2014 yougatup
  42. 42. Basic Arithmetic Euclids Rule gcd , = gcd( , ) gcd 248, 32 gcd 24, 32 gcd 32, 24 gcd(8, 24) POSCAT Seminar 1-42 9 July 2014 yougatup
  43. 43. Basic Arithmetic Euclids Rule gcd , = gcd( , ) gcd 248, 32 gcd 24, 32 gcd 32, 24 gcd 8, 24 gcd(24, 8) POSCAT Seminar 1-43 9 July 2014 yougatup
  44. 44. Basic Arithmetic Euclids Rule gcd , = gcd( , ) gcd 248, 32 gcd 24, 32 gcd 32, 24 gcd 8, 24 gcd(24, 8) POSCAT Seminar 1-44 9 July 2014 yougatup 8 divides 24 ! Therefore, gcd 24, 8 = 8
  45. 45. Basic Arithmetic Euclids Rule gcd , = gcd( , ) How long does it takes ? POSCAT Seminar 1-45 9 July 2014 yougatup
  46. 46. Basic Arithmetic Euclids Rule gcd , = gcd( , ) How long does it takes ? Claim. If then < /2 Consider the cases /2 and > /2 POSCAT Seminar 1-46 9 July 2014 yougatup
  47. 47. Basic Arithmetic Euclids Rule gcd , = gcd( , ) How long does it takes ? Claim. If then /2 Consider the cases /2 and > /2 If /2 then < /2 > /2 then = < /2 POSCAT Seminar 1-47 9 July 2014 yougatup
  48. 48. Basic Arithmetic Euclids Rule gcd , = gcd( , ) How long does it takes ? After two consecutive round, a and b are at least half O( ) POSCAT Seminar 1-48 9 July 2014 yougatup
  49. 49. Primarity Testing Problem Definition Given p, determine whether p is prime number or not Given a interval [s, e], show all of the prime numbers in the interval Approach Nave approach Eratosthenes seive POSCAT Seminar 1-49 9 July 2014 yougatup
  50. 50. Primarity Testing Given p, determine whether p is prime number or not Nave approach For all 2 1, test whether divides p If there is such , then p is NOT prime number Otherwise, p is prime number Verification : Is this algorithm true ? Efficiency : How long does it takes ? POSCAT Seminar 1-50 9 July 2014 yougatup
  51. 51. Primarity Testing Given p, determine whether p is prime number or not Nave approach For all 2 1, test whether divides p If there is such , then p is NOT prime number Otherwise, p is prime number Verification : Is this algorithm true ? By definition of prime number Efficiency : How long does it takes ? O() POSCAT Seminar 1-51 9 July 2014 yougatup
  52. 52. Primarity Testing Given p, determine whether p is prime number or not Nave approach For all 2 1, test whether divides p If there is such , then p is NOT prime number Otherwise, p is prime number Verification : Is this algorithm true ? By definition of prime number Efficiency : How long does it takes ? O() POSCAT Seminar 1-52 9 July 2014 yougatup Is there another algorithm faster ?
  53. 53. Primarity Testing Given p, determine whether p is prime number or not We dont have to consider all such ! It is sufficient to consider 2 , Why ? Verification : Is this algorithm true ? By definition of prime number Efficiency : How long does it takes ? O() POSCAT Seminar 1-53 9 July 2014 yougatup
  54. 54. Primarity Testing Given p, determine whether p is prime number or not We dont have to consider all such ! It is sufficient to consider 2 , Why ? If p is tested as prime number when > , It must be tested before ! Verification : Is this algorithm true ? By definition of prime number Efficiency : How long does it takes ? O() POSCAT Seminar 1-54 9 July 2014 yougatup
  55. 55. Primarity Testing Given p, determine whether p is prime number or not We dont have to consider all such ! It is sufficient to consider 2 , Why ? If p is tested as prime number when > , It must be tested before ! Verification : Is this algorithm true ? By definition of prime number Efficiency : How long does it takes ? O() POSCAT Seminar 1-55 9 July 2014 yougatup
  56. 56. Given a interval [s, e], show all of the prime numbers in the interval Nave approach For all numbers in the interval, test it Verification : Is this algorithm true ? Trivial Efficiency : How long does it takes ? O() POSCAT Seminar 1-56 9 July 2014 yougatup Primarity Testing
  57. 57. Given a interval [s, e], show all of the prime numbers in the interval Nave approach For all numbers in the interval, test it Verification : Is this algorithm true ? Trivial Efficiency : How long does it takes ? O() POSCAT Seminar 1-57 9 July 2014 yougatup Is there another algorithm faster ? Primarity Testing
  58. 58. Eratosthenes seive Simple Algorithm 1. 1 is not a prime number by definition 2. Pick the smallest value among we have, which is 2 3. Erase all the numbers divided by 2 ( except 2 ) 4. Pick the smallest value among we have, which is 3 5. Erase all the numbers divided by 3 ( except 3 ) 6. Repeat this procedure POSCAT Seminar 1-58 9 July 2014 yougatup
  59. 59. Eratosthenes seive Simple Algorithm POSCAT Seminar 1-59 9 July 2014 yougatup 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  60. 60. Eratosthenes seive Simple Algorithm 1 is not a prime number by definition POSCAT Seminar 1-60 9 July 2014 yougatup 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  61. 61. Eratosthenes seive Simple Algorithm Pick the smallest value among we have, which is 2 POSCAT Seminar 1-61 9 July 2014 yougatup 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  62. 62. Eratosthenes seive Simple Algorithm Erase all the numbers divided by 2 ( except 2 ) POSCAT Seminar 1-62 9 July 2014 yougatup 2 3 5 7 9 11 13 15 17
  63. 63. Eratosthenes seive Simple Algorithm Pick the smallest value among we have, which is 3 POSCAT Seminar 1-63 9 July 2014 yougatup 2 3 5 7 9 11 13 15 17
  64. 64. Eratosthenes seive Simple Algorithm Erase all the numbers divided by 3 ( except 3 ) POSCAT Seminar 1-64 9 July 2014 yougatup 2 3 5 7 11 13 17
  65. 65. Eratosthenes seive Simple Algorithm Pick the smallest value among we have, which is 5 POSCAT Seminar 1-65 9 July 2014 yougatup 2 3 5 7 11 13 17
  66. 66. Eratosthenes seive Simple Algorithm Erase all the numbers divided by 5 ( except 5 ) POSCAT Seminar 1-66 9 July 2014 yougatup 2 3 5 7 11 13 17
  67. 67. Eratosthenes seive Simple Algorithm Repeat this procedure POSCAT Seminar 1-67 9 July 2014 yougatup 2 3 5 7 11 13 17
  68. 68. Eratosthenes seive Analysis Verification : Is this algorithm true ? It looks like Efficiency : How long does it takes ? POSCAT Seminar 1-68 9 July 2014 yougatup
  69. 69. Eratosthenes seive Analysis Verification : Is this algorithm true ? It looks like Efficiency : How long does it takes ? Suppose that we want to find all the prime numbers in [1, n] Lets focus on a integer in the interval Then is clicked as many as the number of divisor of It must be bounded by O(log ) for each Therefore, It takes O( ) POSCAT Seminar 1-69 9 July 2014 yougatup Much better than O() !
  70. 70. Bipartite Matching Problem Definition (weak) Maximize the number of matched pair on bipartite graph POSCAT Seminar 1-70 9 July 2014 yougatup 1 2 3 4 1 2 3 4
  71. 71. Bipartite Matching Problem Definition (weak) Maximize the number of matched pair on bipartite graph POSCAT Seminar 1-71 9 July 2014 yougatup 1 2 3 4 1 2 3 4
  72. 72. Stable Matching Problem Definition (weak) N ? POSCAT Seminar 1-72 9 July 2014 yougatup 1 2 3 1 2 3 1 3 1 3
  73. 73. Stable Matching Problem Definition (weak) N ? POSCAT Seminar 1-73 9 July 2014 yougatup 1 2 3 1 2 3 ??
  74. 74. Stable Matching Problem Definition (weak) N ? ? POSCAT Seminar 1-74 9 July 2014 yougatup
  75. 75. Stable Matching Problem Definition (weak) N ? ? Yes ! 2012 (Gale-Shapely Algorithm) POSCAT Seminar 1-75 9 July 2014 yougatup
  76. 76. Stable Matching Problem Definition (weak) 1. 2. 3. 4. 5. ! POSCAT Seminar 1-76 9 July 2014 yougatup
  77. 77. Stable Matching Correctness Is it terminate ? // ? Is there any lonely man or woman ? // ? Is it stable ? // ? POSCAT Seminar 1-77 9 July 2014 yougatup
  78. 78. Stable Matching Correctness Is it terminate ? // ? POSCAT Seminar 1-78 9 July 2014 yougatup
  79. 79. Stable Matching Correctness Is it terminate ? // ? n , . . POSCAT Seminar 1-79 9 July 2014 yougatup
  80. 80. Stable Matching Correctness Is there any lonely man or woman ? // ? POSCAT Seminar 1-80 9 July 2014 yougatup
  81. 81. Stable Matching Correctness Is there any lonely man or woman ? // ? . . n-1 . . . n-1 . POSCAT Seminar 1-81 9 July 2014 yougatup
  82. 82. Stable Matching Correctness Is it stable ? // ? POSCAT Seminar 1-82 9 July 2014 yougatup
  83. 83. Stable Matching Correctness Is it stable ? // ? . X, Y . Y X . X Y . . . . POSCAT Seminar 1-83 9 July 2014 yougatup
  84. 84. Question ? To-do List POSCAT Seminar 1-84 9 July 2014 yougatup