SlideShare a Scribd company logo
POSCAT Seminar 2 :
Algorithm Verification & Efficiency
yougatup @ POSCAT
1
Topic
 Topic today
− Problem Solving Procedure
• Algorithm Verification
• Computational Efficiency
− Basic arithmetic
• Multiplication
• Power
• Greatest Common Divisor
− Primarity Testing
• Naïve approach
• Eratosthenes’ sieve
POSCAT Seminar 1-2
9 July 2014
yougatup
− Stable Matching
− Implementation
• Basic implementation
• Covering today’s topic
Problem Solving Procedure
 문제를 푸는 과정
− 알고리즘을 개발한 후에 이 알고리즘이 정확하다는 것을 증명
− 이 알고리즘이 충분히 빠른 알고리즘인지를 생각
− 괜찮은 알고리즘이면 위의 알고리즘을 오류 없이 구현
 정확성의 증명과 효율성
− 알고리즘의 정확성에 대한 수학적 증명
− 알고리즘의 시간이 얼마나 걸릴지 계산하는 과정
POSCAT Seminar 1-3
9 July 2014
yougatup
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Verification : Is this algorithm true ?
Efficiency : How long does it takes ?
POSCAT Seminar 1-4
9 July 2014
yougatup
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Verification : Is this algorithm true ?
POSCAT Seminar 1-5
9 July 2014
yougatup
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Verification : Is this algorithm true ?
POSCAT Seminar 1-6
9 July 2014
yougatup
Proof : use Mathematical Induction
𝑥 ∙ 𝑦 = 𝑥 + 𝑥 + ⋯ + 𝑥
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-7
9 July 2014
yougatup
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-8
9 July 2014
yougatup
What is the unit ?
Computational Efficiency
 알고리즘의 대략적인 연산횟수를 계산
− 연산을 오래 하는 알고리즘이면 시간도 더 느릴 것이다
− 사칙연산, 비교연산 등 연산에 관계없이 모두 1번이라 생각
− 데이터 크기에 따라 연산 횟수가 달라짐  n에 대한 함수 필요
− 정확하게는 세기 어려움
몇 번의 연산이 필요한가 ?
POSCAT Seminar 1-9
9 July 2014
yougatup
Computational Efficiency
 알고리즘의 대략적인 연산횟수를 계산
− 연산을 오래 하는 알고리즘이면 시간도 더 느릴 것이다
− 사칙연산, 비교연산 등 연산에 관계없이 모두 1번이라 생각
− 데이터 크기에 따라 연산 횟수가 달라짐  n에 대한 함수 필요
− 정확하게는 세기 어려움
몇 번의 연산이 필요한가 ? 약 n번
POSCAT Seminar 1-10
9 July 2014
yougatup
Computational Efficiency
 알고리즘의 대략적인 연산횟수를 계산
− 연산을 오래 하는 알고리즘이면 시간도 더 느릴 것이다
− 사칙연산, 비교연산 등 연산에 관계없이 모두 1번이라 생각
− 데이터 크기에 따라 연산 횟수가 달라짐  n에 대한 함수 필요
− 정확하게는 세기 어려움
몇 번의 연산이 필요한가 ? O(𝒏)
POSCAT Seminar 1-11
9 July 2014
yougatup
Computational Efficiency
 Example
POSCAT Seminar 1-12
9 July 2014
yougatup
Computational Efficiency
 Example
POSCAT Seminar 1-13
9 July 2014
yougatup
O(𝑛2
+ 𝑛)
Computational Efficiency
 Example
POSCAT Seminar 1-14
9 July 2014
yougatup
O(𝒏 𝟐
)
Computational Efficiency
 Example
POSCAT Seminar 1-15
9 July 2014
yougatup
Computational Efficiency
 Example
POSCAT Seminar 1-16
9 July 2014
yougatup
O(3 ∙ { 𝑛 − 1 + 𝑛 − 2 + ⋯ + 1})
swap loop
Computational Efficiency
 Example
POSCAT Seminar 1-17
9 July 2014
yougatup
O(3 ∙ {
𝑛 ∙ (𝑛−1)
2
})
Computational Efficiency
 Example
POSCAT Seminar 1-18
9 July 2014
yougatup
O(3 ∙ {
𝑛2
2
})
Computational Efficiency
 Example
POSCAT Seminar 1-19
9 July 2014
yougatup
O(3𝑛2)
Computational Efficiency
 Example
POSCAT Seminar 1-20
9 July 2014
yougatup
O(𝒏 𝟐)
Computational Efficiency
 Example
POSCAT Seminar 1-21
9 July 2014
yougatup
O(𝒏 𝟐)
사실 대부분의 경우에는 최고차 항만 고려하면 됨
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-22
9 July 2014
yougatup
What is the unit ?
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 !
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-24
9 July 2014
yougatup
So, what is the efficiency ?
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-25
9 July 2014
yougatup
So, what is the efficiency ?
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
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-27
9 July 2014
yougatup
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-28
9 July 2014
yougatup
O(y)
Basic Arithmetic
 Multiplication
𝑥 ∙ 𝑦 =
𝑥
𝑥 ∙ 𝑦 − 1 + 𝑥
𝑖𝑓 𝑦 = 1
𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Efficiency : How long does it takes ?
POSCAT Seminar 1-29
9 July 2014
yougatup
O(y)
Done!
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 ?
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
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
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 하면 될걸 무슨 이런 헛짓을…
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
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
Claim. G = gcd 𝑥, 𝑦 = gcd 𝑥 − 𝑦, 𝑦 𝑖𝑓 𝑥 ≥ 𝑦
Proof.
POSCAT Seminar 1-35
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s 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
Basic Arithmetic
 Euclid’s 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
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
Then G = gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦 , 𝑦) 𝑖𝑓 𝑥 ≥ 𝑦
POSCAT Seminar 1-38
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
gcd 248, 32
POSCAT Seminar 1-39
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
gcd 248, 32
gcd(24, 32)
POSCAT Seminar 1-40
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
gcd 248, 32
gcd 24, 32
gcd(32, 24)
POSCAT Seminar 1-41
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
gcd 248, 32
gcd 24, 32
gcd 32, 24
gcd(8, 24)
POSCAT Seminar 1-42
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s 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
Basic Arithmetic
 Euclid’s 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
Basic Arithmetic
 Euclid’s Rule
gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦)
How long does it takes ?
POSCAT Seminar 1-45
9 July 2014
yougatup
Basic Arithmetic
 Euclid’s 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
Basic Arithmetic
 Euclid’s 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
Basic Arithmetic
 Euclid’s 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
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
− Naïve approach
− Eratosthenes’ seive
POSCAT Seminar 1-49
9 July 2014
yougatup
Primarity Testing
Given p, determine whether p is prime number or not
 Naïve 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
Primarity Testing
Given p, determine whether p is prime number or not
 Naïve 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
Primarity Testing
Given p, determine whether p is prime number or not
 Naïve 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 ?
Primarity Testing
Given p, determine whether p is prime number or not
 We don’t 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
Primarity Testing
Given p, determine whether p is prime number or not
 We don’t 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
Primarity Testing
Given p, determine whether p is prime number or not
 We don’t 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
Given a interval [s, e], show all of the prime numbers in the interval
 Naïve 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
Given a interval [s, e], show all of the prime numbers in the interval
 Naïve 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
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
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
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
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
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
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
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
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
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
Eratosthenes’ seive
 Simple Algorithm
Repeat this procedure
POSCAT Seminar 1-67
9 July 2014
yougatup
2 3 5 7 11 13 17
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
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]
Let’s 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(𝑛√𝑛) !
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
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
Stable Matching
 Problem Definition (weak)
N명의 남자와 여자가 미팅을 하기 위해서 만남
남자와 여자 모두 원하는 상대방의 우선순위를 정함
서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ?
POSCAT Seminar 1-72
9 July 2014
yougatup
1
2
3
1
2
3
난 1번보다 3번이 더 좋은데…난 1번보다 3번이 더 좋은데…
男 女
Stable Matching
 Problem Definition (weak)
N명의 남자와 여자가 미팅을 하기 위해서 만남
남자와 여자 모두 원하는 상대방의 우선순위를 정함
서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ?
POSCAT Seminar 1-73
9 July 2014
yougatup
1
2
3
1
2
3
男 女
도망ㅋ
헐
헐
??
Stable Matching
 Problem Definition (weak)
N명의 남자와 여자가 미팅을 하기 위해서 만남
남자와 여자 모두 원하는 상대방의 우선순위를 정함
서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ?
이런 불상사가 나지 않도록 짝을 짓는 것이 가능한가?
POSCAT Seminar 1-74
9 July 2014
yougatup
Stable Matching
 Problem Definition (weak)
N명의 남자와 여자가 미팅을 하기 위해서 만남
남자와 여자 모두 원하는 상대방의 우선순위를 정함
서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ?
이런 불상사가 나지 않도록 짝을 짓는 것이 가능한가?
 Yes ! 가능하다는 것을 해를 구하는 알고리즘으로 증명
2012년 노벨 경제학상을 받게 한 알고리즘 (Gale-Shapely Algorithm)
POSCAT Seminar 1-75
9 July 2014
yougatup
Stable Matching
 Problem Definition (weak)
1. 처음에 남성이 모두 가장 선호하는 여성에게 프로포즈를 함
2. 여성이 그 중 가장 마음에 드는 남성을 고르고 나머지는 퇴짜
3. 퇴짜맞은 남성은 그 다음으로 선호하는 여성이 파트너가 있던
말던 프로포즈를 함
4. 여성은 현재 자신의 파트너보다 프로포즈 한 남성이 더 마음에
든다면 자신의 파트너에게 퇴짜를 놓음
5. 이 과정을 계속해서 반복 !
POSCAT Seminar 1-76
9 July 2014
yougatup
Stable Matching
 Correctness
− Is it terminate ? // 언젠간 종료하는가 ?
− Is there any lonely man or woman ? // 짝 없는 사람이 존재하는가 ?
− Is it stable ? // 불상사가 없는가 ?
POSCAT Seminar 1-77
9 July 2014
yougatup
Stable Matching
 Correctness
− Is it terminate ? // 언젠간 종료하는가 ?
POSCAT Seminar 1-78
9 July 2014
yougatup
Stable Matching
 Correctness
− Is it terminate ? // 언젠간 종료하는가 ?
각 남성은 많아야 n명에게 프로포즈를 하고, 같은 사람에게 두 번 하지 않는다.
따라서 이 과정은 언젠간 종료된다.
POSCAT Seminar 1-79
9 July 2014
yougatup
Stable Matching
 Correctness
− Is there any lonely man or woman ? // 짝 없는 사람이 존재하는가 ?
POSCAT Seminar 1-80
9 July 2014
yougatup
Stable Matching
 Correctness
− Is there any lonely man or woman ? // 짝 없는 사람이 존재하는가 ?
여성이 짝이 없다고 가정하자. 그렇다면 한 명도 프로포즈한 남성이 없다.
그러면 모든 남성이 n-1명의 여성과 짝을 이룬다는 것이므로 모순.
남성이 짝이 없다고 가정하자. 그렇다면 모두 퇴짜를 맞았다는 것이다.
그러면 모든 여성이 n-1명의 남성과 짝을 이룬다는 것이므로 모순.
POSCAT Seminar 1-81
9 July 2014
yougatup
Stable Matching
 Correctness
− Is it stable ? // 불상사가 없는가 ?
POSCAT Seminar 1-82
9 July 2014
yougatup
Stable Matching
 Correctness
− Is it stable ? // 불상사가 없는가 ?
불상사가 생긴 남성과 여성이 존재한다고 가정하자.
편의상 현재 파트너를 X, 불상사가 생기는 파트너를 Y 이라고 하자.
남성은 Y를 X보다 더 좋아한다. 그러면 X보다 Y에게 더 먼저 프로포즈 했을 것.
여성은 현재 이 남성과 파트너가 아니므로 퇴짜를 놓았다는 뜻이다.
하지만 여성 역시 현재 자신의 파트너보다 이 남성이 더 좋은 상황이다.
더 좋은 사람을 퇴짜 놓은 상황이므로 모순.
POSCAT Seminar 1-83
9 July 2014
yougatup
Question ?
 To-do List
− 코딩 합시다 
POSCAT Seminar 1-84
9 July 2014
yougatup

More Related Content

Viewers also liked

Poscat seminar 10
Poscat seminar 10Poscat seminar 10
Poscat seminar 10
Hyungyu Shin
 
Poscat seminar 11
Poscat seminar 11Poscat seminar 11
Poscat seminar 11
Hyungyu Shin
 
Poscat seminar 8
Poscat seminar 8Poscat seminar 8
Poscat seminar 8
Hyungyu Shin
 
Poscat seminar 9
Poscat seminar 9Poscat seminar 9
Poscat seminar 9
Hyungyu Shin
 
Poscat seminar 3-1
Poscat seminar 3-1Poscat seminar 3-1
Poscat seminar 3-1
Hyungyu Shin
 
How to Use Slideshare
How to Use SlideshareHow to Use Slideshare
How to Use Slideshare
Converting Copy
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
SlideShare
 

Viewers also liked (9)

Poscat seminar 10
Poscat seminar 10Poscat seminar 10
Poscat seminar 10
 
Poscat seminar 11
Poscat seminar 11Poscat seminar 11
Poscat seminar 11
 
Poscat seminar 8
Poscat seminar 8Poscat seminar 8
Poscat seminar 8
 
Poscat seminar 9
Poscat seminar 9Poscat seminar 9
Poscat seminar 9
 
Poscat seminar 3-1
Poscat seminar 3-1Poscat seminar 3-1
Poscat seminar 3-1
 
How to Use Slideshare
How to Use SlideshareHow to Use Slideshare
How to Use Slideshare
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to Poscat seminar 2

jake.pptx
jake.pptxjake.pptx
jake.pptx
Noor559551
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
Ashutosh Satapathy
 
Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)
Shiang-Yun Yang
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
MAHERMOHAMED27
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
rajinooka
 
Asymptotic Analysis
Asymptotic AnalysisAsymptotic Analysis
Asymptotic Analysis
sonugupta
 
GECCO-2014 Learning Classifier Systems: A Gentle Introduction
GECCO-2014 Learning Classifier Systems: A Gentle IntroductionGECCO-2014 Learning Classifier Systems: A Gentle Introduction
GECCO-2014 Learning Classifier Systems: A Gentle Introduction
Pier Luca Lanzi
 
Writing a SAT solver as a hobby project
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby project
Masahiro Sakai
 
DISMATH_Part2
DISMATH_Part2DISMATH_Part2
DISMATH_Part2
Melvin Cabatuan
 
2021 1학기 정기 세미나 2주차
2021 1학기 정기 세미나 2주차2021 1학기 정기 세미나 2주차
2021 1학기 정기 세미나 2주차
Moonki Choi
 
Abhik-Satish-dagstuhl
Abhik-Satish-dagstuhlAbhik-Satish-dagstuhl
Abhik-Satish-dagstuhl
Abhik Roychoudhury
 
Stamp breizhcamp 2019
Stamp breizhcamp 2019Stamp breizhcamp 2019
Stamp breizhcamp 2019
Caroline Landry
 
PPT - Discovering Reinforcement Learning Algorithms
PPT - Discovering Reinforcement Learning AlgorithmsPPT - Discovering Reinforcement Learning Algorithms
PPT - Discovering Reinforcement Learning Algorithms
Jisang Yoon
 
A dynamical system for PageRank with time-dependent teleportation
A dynamical system for PageRank with time-dependent teleportationA dynamical system for PageRank with time-dependent teleportation
A dynamical system for PageRank with time-dependent teleportation
David Gleich
 
Ads unit 3 ppt
Ads unit 3 pptAds unit 3 ppt
Ads unit 3 ppt
praveena p
 
Dismath part2 2013
Dismath part2 2013Dismath part2 2013
Dismath part2 2013
Melvin Cabatuan
 
GECCO 2014 - Learning Classifier System Tutorial
GECCO 2014 - Learning Classifier System TutorialGECCO 2014 - Learning Classifier System Tutorial
GECCO 2014 - Learning Classifier System Tutorial
Pier Luca Lanzi
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
jinalgoti
 
Parallel Algorithms K – means Clustering
Parallel Algorithms K – means ClusteringParallel Algorithms K – means Clustering
Parallel Algorithms K – means Clustering
Andreina Uzcategui
 
MachineLearning_QLearningCircuit
MachineLearning_QLearningCircuitMachineLearning_QLearningCircuit
MachineLearning_QLearningCircuit
Sean Williams
 

Similar to Poscat seminar 2 (20)

jake.pptx
jake.pptxjake.pptx
jake.pptx
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
 
Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)Aaex4 group2(中英夾雜)
Aaex4 group2(中英夾雜)
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 
Asymptotic Analysis
Asymptotic AnalysisAsymptotic Analysis
Asymptotic Analysis
 
GECCO-2014 Learning Classifier Systems: A Gentle Introduction
GECCO-2014 Learning Classifier Systems: A Gentle IntroductionGECCO-2014 Learning Classifier Systems: A Gentle Introduction
GECCO-2014 Learning Classifier Systems: A Gentle Introduction
 
Writing a SAT solver as a hobby project
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby project
 
DISMATH_Part2
DISMATH_Part2DISMATH_Part2
DISMATH_Part2
 
2021 1학기 정기 세미나 2주차
2021 1학기 정기 세미나 2주차2021 1학기 정기 세미나 2주차
2021 1학기 정기 세미나 2주차
 
Abhik-Satish-dagstuhl
Abhik-Satish-dagstuhlAbhik-Satish-dagstuhl
Abhik-Satish-dagstuhl
 
Stamp breizhcamp 2019
Stamp breizhcamp 2019Stamp breizhcamp 2019
Stamp breizhcamp 2019
 
PPT - Discovering Reinforcement Learning Algorithms
PPT - Discovering Reinforcement Learning AlgorithmsPPT - Discovering Reinforcement Learning Algorithms
PPT - Discovering Reinforcement Learning Algorithms
 
A dynamical system for PageRank with time-dependent teleportation
A dynamical system for PageRank with time-dependent teleportationA dynamical system for PageRank with time-dependent teleportation
A dynamical system for PageRank with time-dependent teleportation
 
Ads unit 3 ppt
Ads unit 3 pptAds unit 3 ppt
Ads unit 3 ppt
 
Dismath part2 2013
Dismath part2 2013Dismath part2 2013
Dismath part2 2013
 
GECCO 2014 - Learning Classifier System Tutorial
GECCO 2014 - Learning Classifier System TutorialGECCO 2014 - Learning Classifier System Tutorial
GECCO 2014 - Learning Classifier System Tutorial
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Parallel Algorithms K – means Clustering
Parallel Algorithms K – means ClusteringParallel Algorithms K – means Clustering
Parallel Algorithms K – means Clustering
 
MachineLearning_QLearningCircuit
MachineLearning_QLearningCircuitMachineLearning_QLearningCircuit
MachineLearning_QLearningCircuit
 

Recently uploaded

Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 

Recently uploaded (20)

Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 

Poscat seminar 2

  • 1. POSCAT Seminar 2 : Algorithm Verification & Efficiency yougatup @ POSCAT 1
  • 2. Topic  Topic today − Problem Solving Procedure • Algorithm Verification • Computational Efficiency − Basic arithmetic • Multiplication • Power • Greatest Common Divisor − Primarity Testing • Naïve approach • Eratosthenes’ sieve POSCAT Seminar 1-2 9 July 2014 yougatup − Stable Matching − Implementation • Basic implementation • Covering today’s topic
  • 3. Problem Solving Procedure  문제를 푸는 과정 − 알고리즘을 개발한 후에 이 알고리즘이 정확하다는 것을 증명 − 이 알고리즘이 충분히 빠른 알고리즘인지를 생각 − 괜찮은 알고리즘이면 위의 알고리즘을 오류 없이 구현  정확성의 증명과 효율성 − 알고리즘의 정확성에 대한 수학적 증명 − 알고리즘의 시간이 얼마나 걸릴지 계산하는 과정 POSCAT Seminar 1-3 9 July 2014 yougatup
  • 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. Basic Arithmetic  Multiplication 𝑥 ∙ 𝑦 = 𝑥 𝑥 ∙ 𝑦 − 1 + 𝑥 𝑖𝑓 𝑦 = 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Verification : Is this algorithm true ? POSCAT Seminar 1-5 9 July 2014 yougatup
  • 6. Basic Arithmetic  Multiplication 𝑥 ∙ 𝑦 = 𝑥 𝑥 ∙ 𝑦 − 1 + 𝑥 𝑖𝑓 𝑦 = 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Verification : Is this algorithm true ? POSCAT Seminar 1-6 9 July 2014 yougatup Proof : use Mathematical Induction 𝑥 ∙ 𝑦 = 𝑥 + 𝑥 + ⋯ + 𝑥
  • 7. Basic Arithmetic  Multiplication 𝑥 ∙ 𝑦 = 𝑥 𝑥 ∙ 𝑦 − 1 + 𝑥 𝑖𝑓 𝑦 = 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Efficiency : How long does it takes ? POSCAT Seminar 1-7 9 July 2014 yougatup
  • 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. Computational Efficiency  알고리즘의 대략적인 연산횟수를 계산 − 연산을 오래 하는 알고리즘이면 시간도 더 느릴 것이다 − 사칙연산, 비교연산 등 연산에 관계없이 모두 1번이라 생각 − 데이터 크기에 따라 연산 횟수가 달라짐  n에 대한 함수 필요 − 정확하게는 세기 어려움 몇 번의 연산이 필요한가 ? POSCAT Seminar 1-9 9 July 2014 yougatup
  • 10. Computational Efficiency  알고리즘의 대략적인 연산횟수를 계산 − 연산을 오래 하는 알고리즘이면 시간도 더 느릴 것이다 − 사칙연산, 비교연산 등 연산에 관계없이 모두 1번이라 생각 − 데이터 크기에 따라 연산 횟수가 달라짐  n에 대한 함수 필요 − 정확하게는 세기 어려움 몇 번의 연산이 필요한가 ? 약 n번 POSCAT Seminar 1-10 9 July 2014 yougatup
  • 11. Computational Efficiency  알고리즘의 대략적인 연산횟수를 계산 − 연산을 오래 하는 알고리즘이면 시간도 더 느릴 것이다 − 사칙연산, 비교연산 등 연산에 관계없이 모두 1번이라 생각 − 데이터 크기에 따라 연산 횟수가 달라짐  n에 대한 함수 필요 − 정확하게는 세기 어려움 몇 번의 연산이 필요한가 ? O(𝒏) POSCAT Seminar 1-11 9 July 2014 yougatup
  • 12. Computational Efficiency  Example POSCAT Seminar 1-12 9 July 2014 yougatup
  • 13. Computational Efficiency  Example POSCAT Seminar 1-13 9 July 2014 yougatup O(𝑛2 + 𝑛)
  • 14. Computational Efficiency  Example POSCAT Seminar 1-14 9 July 2014 yougatup O(𝒏 𝟐 )
  • 15. Computational Efficiency  Example POSCAT Seminar 1-15 9 July 2014 yougatup
  • 16. Computational Efficiency  Example POSCAT Seminar 1-16 9 July 2014 yougatup O(3 ∙ { 𝑛 − 1 + 𝑛 − 2 + ⋯ + 1}) swap loop
  • 17. Computational Efficiency  Example POSCAT Seminar 1-17 9 July 2014 yougatup O(3 ∙ { 𝑛 ∙ (𝑛−1) 2 })
  • 18. Computational Efficiency  Example POSCAT Seminar 1-18 9 July 2014 yougatup O(3 ∙ { 𝑛2 2 })
  • 19. Computational Efficiency  Example POSCAT Seminar 1-19 9 July 2014 yougatup O(3𝑛2)
  • 20. Computational Efficiency  Example POSCAT Seminar 1-20 9 July 2014 yougatup O(𝒏 𝟐)
  • 21. Computational Efficiency  Example POSCAT Seminar 1-21 9 July 2014 yougatup O(𝒏 𝟐) 사실 대부분의 경우에는 최고차 항만 고려하면 됨
  • 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. 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. 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. 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. 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. Basic Arithmetic  Multiplication 𝑥 ∙ 𝑦 = 𝑥 𝑥 ∙ 𝑦 − 1 + 𝑥 𝑖𝑓 𝑦 = 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Efficiency : How long does it takes ? POSCAT Seminar 1-27 9 July 2014 yougatup
  • 28. Basic Arithmetic  Multiplication 𝑥 ∙ 𝑦 = 𝑥 𝑥 ∙ 𝑦 − 1 + 𝑥 𝑖𝑓 𝑦 = 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Efficiency : How long does it takes ? POSCAT Seminar 1-28 9 July 2014 yougatup O(y)
  • 29. Basic Arithmetic  Multiplication 𝑥 ∙ 𝑦 = 𝑥 𝑥 ∙ 𝑦 − 1 + 𝑥 𝑖𝑓 𝑦 = 1 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Efficiency : How long does it takes ? POSCAT Seminar 1-29 9 July 2014 yougatup O(y) Done!
  • 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. 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. 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. 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. 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. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) Claim. G = gcd 𝑥, 𝑦 = gcd 𝑥 − 𝑦, 𝑦 𝑖𝑓 𝑥 ≥ 𝑦 Proof. POSCAT Seminar 1-35 9 July 2014 yougatup
  • 36. Basic Arithmetic  Euclid’s 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. Basic Arithmetic  Euclid’s 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. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) Then G = gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦 , 𝑦) 𝑖𝑓 𝑥 ≥ 𝑦 POSCAT Seminar 1-38 9 July 2014 yougatup
  • 39. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) gcd 248, 32 POSCAT Seminar 1-39 9 July 2014 yougatup
  • 40. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) gcd 248, 32 gcd(24, 32) POSCAT Seminar 1-40 9 July 2014 yougatup
  • 41. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) gcd 248, 32 gcd 24, 32 gcd(32, 24) POSCAT Seminar 1-41 9 July 2014 yougatup
  • 42. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) gcd 248, 32 gcd 24, 32 gcd 32, 24 gcd(8, 24) POSCAT Seminar 1-42 9 July 2014 yougatup
  • 43. Basic Arithmetic  Euclid’s 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. Basic Arithmetic  Euclid’s 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. Basic Arithmetic  Euclid’s Rule gcd 𝑥, 𝑦 = gcd(𝑥 𝑚𝑜𝑑 𝑦, 𝑦) How long does it takes ? POSCAT Seminar 1-45 9 July 2014 yougatup
  • 46. Basic Arithmetic  Euclid’s 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. Basic Arithmetic  Euclid’s 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. Basic Arithmetic  Euclid’s 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. 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 − Naïve approach − Eratosthenes’ seive POSCAT Seminar 1-49 9 July 2014 yougatup
  • 50. Primarity Testing Given p, determine whether p is prime number or not  Naïve 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. Primarity Testing Given p, determine whether p is prime number or not  Naïve 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. Primarity Testing Given p, determine whether p is prime number or not  Naïve 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. Primarity Testing Given p, determine whether p is prime number or not  We don’t 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. Primarity Testing Given p, determine whether p is prime number or not  We don’t 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. Primarity Testing Given p, determine whether p is prime number or not  We don’t 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. Given a interval [s, e], show all of the prime numbers in the interval  Naïve 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. Given a interval [s, e], show all of the prime numbers in the interval  Naïve 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Eratosthenes’ seive  Simple Algorithm Repeat this procedure POSCAT Seminar 1-67 9 July 2014 yougatup 2 3 5 7 11 13 17
  • 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. 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] Let’s 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. 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. 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. 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. Stable Matching  Problem Definition (weak) N명의 남자와 여자가 미팅을 하기 위해서 만남 남자와 여자 모두 원하는 상대방의 우선순위를 정함 서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ? POSCAT Seminar 1-73 9 July 2014 yougatup 1 2 3 1 2 3 男 女 도망ㅋ 헐 헐 ??
  • 74. Stable Matching  Problem Definition (weak) N명의 남자와 여자가 미팅을 하기 위해서 만남 남자와 여자 모두 원하는 상대방의 우선순위를 정함 서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ? 이런 불상사가 나지 않도록 짝을 짓는 것이 가능한가? POSCAT Seminar 1-74 9 July 2014 yougatup
  • 75. Stable Matching  Problem Definition (weak) N명의 남자와 여자가 미팅을 하기 위해서 만남 남자와 여자 모두 원하는 상대방의 우선순위를 정함 서로 짝이 아닌 두 남녀가 자신의 짝보다 상대방을 더 선호하면 ? 이런 불상사가 나지 않도록 짝을 짓는 것이 가능한가?  Yes ! 가능하다는 것을 해를 구하는 알고리즘으로 증명 2012년 노벨 경제학상을 받게 한 알고리즘 (Gale-Shapely Algorithm) POSCAT Seminar 1-75 9 July 2014 yougatup
  • 76. Stable Matching  Problem Definition (weak) 1. 처음에 남성이 모두 가장 선호하는 여성에게 프로포즈를 함 2. 여성이 그 중 가장 마음에 드는 남성을 고르고 나머지는 퇴짜 3. 퇴짜맞은 남성은 그 다음으로 선호하는 여성이 파트너가 있던 말던 프로포즈를 함 4. 여성은 현재 자신의 파트너보다 프로포즈 한 남성이 더 마음에 든다면 자신의 파트너에게 퇴짜를 놓음 5. 이 과정을 계속해서 반복 ! POSCAT Seminar 1-76 9 July 2014 yougatup
  • 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. Stable Matching  Correctness − Is it terminate ? // 언젠간 종료하는가 ? POSCAT Seminar 1-78 9 July 2014 yougatup
  • 79. Stable Matching  Correctness − Is it terminate ? // 언젠간 종료하는가 ? 각 남성은 많아야 n명에게 프로포즈를 하고, 같은 사람에게 두 번 하지 않는다. 따라서 이 과정은 언젠간 종료된다. POSCAT Seminar 1-79 9 July 2014 yougatup
  • 80. Stable Matching  Correctness − Is there any lonely man or woman ? // 짝 없는 사람이 존재하는가 ? POSCAT Seminar 1-80 9 July 2014 yougatup
  • 81. Stable Matching  Correctness − Is there any lonely man or woman ? // 짝 없는 사람이 존재하는가 ? 여성이 짝이 없다고 가정하자. 그렇다면 한 명도 프로포즈한 남성이 없다. 그러면 모든 남성이 n-1명의 여성과 짝을 이룬다는 것이므로 모순. 남성이 짝이 없다고 가정하자. 그렇다면 모두 퇴짜를 맞았다는 것이다. 그러면 모든 여성이 n-1명의 남성과 짝을 이룬다는 것이므로 모순. POSCAT Seminar 1-81 9 July 2014 yougatup
  • 82. Stable Matching  Correctness − Is it stable ? // 불상사가 없는가 ? POSCAT Seminar 1-82 9 July 2014 yougatup
  • 83. Stable Matching  Correctness − Is it stable ? // 불상사가 없는가 ? 불상사가 생긴 남성과 여성이 존재한다고 가정하자. 편의상 현재 파트너를 X, 불상사가 생기는 파트너를 Y 이라고 하자. 남성은 Y를 X보다 더 좋아한다. 그러면 X보다 Y에게 더 먼저 프로포즈 했을 것. 여성은 현재 이 남성과 파트너가 아니므로 퇴짜를 놓았다는 뜻이다. 하지만 여성 역시 현재 자신의 파트너보다 이 남성이 더 좋은 상황이다. 더 좋은 사람을 퇴짜 놓은 상황이므로 모순. POSCAT Seminar 1-83 9 July 2014 yougatup
  • 84. Question ?  To-do List − 코딩 합시다  POSCAT Seminar 1-84 9 July 2014 yougatup