アルゴリズムイントロダクション 第5.4章

13
Copyright© 2010 tniky1 All rights reserved. Page 1 2010CS勉強会第32010/06/12 tniky1 h:p://www.tniky1.com/

description

アルゴリズムイントロダクション 第5.4章 勉強会資料 下記でPPT版,KEY版も配布してます. http://tniky1.com/study/

Transcript of アルゴリズムイントロダクション 第5.4章

Page 1: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  1

2010年CS勉強会第3回  2010/06/12

tniky1  

h:p://www.tniky1.com/

Page 2: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  2

2010年CS勉強会 アルゴリズムイントロダクション

前回の雇用問題

雇用代理店

・・・・・

 1                2              3           n 現在の秘書best

候補  i  

面談

一番じゃないといけないんですか!?

全員と面談をするのは無駄でしょ!

毎回雇用するのは無駄でしょ!

Page 3: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  3

2010年CS勉強会 アルゴリズムイントロダクション

5.4.4  オンライン雇用問題の目的

もう少し実践的な雇用問題にしよう

対応ページの記載

一言で言っちゃうとこれだけ。特に新しい概念とか技法はない(^^;)

Page 4: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  4

2010年CS勉強会 アルゴリズムイントロダクション

オンライン雇用問題

•  方針  – 採用は一度きり  – 最適に近い候補(なるべく優秀な人)を採用できればよい  

– 面談直後に採用の合否を判断  

•  今回の戦略  – 最初の一部 k人 と面談し、その中で最高点を確認する。(採用はしない)  

–  k+1人目以降で今までの最高点を最初に更新した人を採用  

採用しない最初の面談回数は何回がよい?  最良の人を雇用する確率は?  p109

Page 5: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  5

2010年CS勉強会 アルゴリズムイントロダクション

オンライン雇用問題 アルゴリズム

5.4 Probabilistic analysis and further uses of indicator random variables 115

then rejecting the first k applicants, and hiring the first applicant thereafter who hasa higher score than all preceding applicants. If it turns out that the best-qualifiedapplicant was among the first k interviewed, then we will hire the nth applicant.This strategy is formalized in the procedure ON-LINE-MAXIMUM(k, n), whichappears below. Procedure ON-LINE-MAXIMUM returns the index of the candidatewe wish to hire.

ON-LINE-MAXIMUM(k, n)

1 bestscore ! "#2 for i ! 1 to k3 do if score(i) > bestscore4 then bestscore ! score(i)5 for i ! k + 1 to n6 do if score(i) > bestscore7 then return i8 return n

We wish to determine, for each possible value of k, the probability that wehire the most qualified applicant. We will then choose the best possible k, andimplement the strategy with that value. For the moment, assume that k is fixed.Let M( j) = max1$i$ j {score(i)} denote the maximum score among applicants 1through j . Let S be the event that we succeed in choosing the best-qualifiedapplicant, and let Si be the event that we succeed when the best-qualified appli-cant is the i th one interviewed. Since the various Si are disjoint, we have thatPr {S} = !n

i=1 Pr {Si}. Noting that we never succeed when the best-qualified ap-plicant is one of the first k, we have that Pr {Si} = 0 for i = 1, 2, . . . , k. Thus, weobtain

Pr {S} =n"

i=k+1

Pr {Si} . (5.13)

We now compute Pr {Si}. In order to succeed when the best-qualified applicantis the i th one, two things must happen. First, the best-qualified applicant must bein position i , an event which we denote by Bi . Second, the algorithm must notselect any of the applicants in positions k +1 through i "1, which happens only if,for each j such that k + 1 $ j $ i " 1, we find that score( j) < bestscore in line 6.(Because scores are unique, we can ignore the possibility of score( j) = bestscore.)In other words, it must be the case that all of the values score(k + 1) throughscore(i "1) are less than M(k); if any are greater than M(k) we will instead returnthe index of the first one that is greater. We use Oi to denote the event that noneof the applicants in position k + 1 through i " 1 are chosen. Fortunately, thetwo events Bi and Oi are independent. The event Oi depends only on the relative

雇用代理店

・・・・・

 1              2                                    k

候補  I  (i≤k)  

面談

k+1        k+2                                              n

・・・

・最高点を確認 ・最高点以上を採用  ・採用すれば終了  ・1~kに最高点者が      いた場合nを採用  

bestscore 候補  I  (i>k)  

・全員と面談しないですむ。  ・雇用は一回ですむ

面談

面談直後に採用の合否を判断という方針のため

最良の雇用者を得る確率は?  kをどのような値にすればよい?  

bestscore

Page 6: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  6

2010年CS勉強会 アルゴリズムイントロダクション

最良の人を雇用する確率

•  最良の人を雇用するという事象をS  •  Sの確率を求め(kに依存)、kをどのような値にすべきか(最良のk)、またその時の確率をみる  

•  i番目の応募者が最高得点の人であり、その人の雇用に成功する事象Si    

–   i =  1,2,•••,k      

–   i =  k+1,•••,n    

5.4 Probabilistic analysis and further uses of indicator random variables 115

then rejecting the first k applicants, and hiring the first applicant thereafter who hasa higher score than all preceding applicants. If it turns out that the best-qualifiedapplicant was among the first k interviewed, then we will hire the nth applicant.This strategy is formalized in the procedure ON-LINE-MAXIMUM(k, n), whichappears below. Procedure ON-LINE-MAXIMUM returns the index of the candidatewe wish to hire.

ON-LINE-MAXIMUM(k, n)

1 bestscore ! "#2 for i ! 1 to k3 do if score(i) > bestscore4 then bestscore ! score(i)5 for i ! k + 1 to n6 do if score(i) > bestscore7 then return i8 return n

We wish to determine, for each possible value of k, the probability that wehire the most qualified applicant. We will then choose the best possible k, andimplement the strategy with that value. For the moment, assume that k is fixed.Let M( j) = max1$i$ j {score(i)} denote the maximum score among applicants 1through j . Let S be the event that we succeed in choosing the best-qualifiedapplicant, and let Si be the event that we succeed when the best-qualified appli-cant is the i th one interviewed. Since the various Si are disjoint, we have thatPr {S} = !n

i=1 Pr {Si}. Noting that we never succeed when the best-qualified ap-plicant is one of the first k, we have that Pr {Si} = 0 for i = 1, 2, . . . , k. Thus, weobtain

Pr {S} =n"

i=k+1

Pr {Si} . (5.13)

We now compute Pr {Si}. In order to succeed when the best-qualified applicantis the i th one, two things must happen. First, the best-qualified applicant must bein position i , an event which we denote by Bi . Second, the algorithm must notselect any of the applicants in positions k +1 through i "1, which happens only if,for each j such that k + 1 $ j $ i " 1, we find that score( j) < bestscore in line 6.(Because scores are unique, we can ignore the possibility of score( j) = bestscore.)In other words, it must be the case that all of the values score(k + 1) throughscore(i "1) are less than M(k); if any are greater than M(k) we will instead returnthe index of the first one that is greater. We use Oi to denote the event that noneof the applicants in position k + 1 through i " 1 are chosen. Fortunately, thetwo events Bi and Oi are independent. The event Oi depends only on the relative

5.4 Probabilistic analysis and further uses of indicator random variables 115

then rejecting the first k applicants, and hiring the first applicant thereafter who hasa higher score than all preceding applicants. If it turns out that the best-qualifiedapplicant was among the first k interviewed, then we will hire the nth applicant.This strategy is formalized in the procedure ON-LINE-MAXIMUM(k, n), whichappears below. Procedure ON-LINE-MAXIMUM returns the index of the candidatewe wish to hire.

ON-LINE-MAXIMUM(k, n)

1 bestscore ! "#2 for i ! 1 to k3 do if score(i) > bestscore4 then bestscore ! score(i)5 for i ! k + 1 to n6 do if score(i) > bestscore7 then return i8 return n

We wish to determine, for each possible value of k, the probability that wehire the most qualified applicant. We will then choose the best possible k, andimplement the strategy with that value. For the moment, assume that k is fixed.Let M( j) = max1$i$ j {score(i)} denote the maximum score among applicants 1through j . Let S be the event that we succeed in choosing the best-qualifiedapplicant, and let Si be the event that we succeed when the best-qualified appli-cant is the i th one interviewed. Since the various Si are disjoint, we have thatPr {S} = !n

i=1 Pr {Si}. Noting that we never succeed when the best-qualified ap-plicant is one of the first k, we have that Pr {Si} = 0 for i = 1, 2, . . . , k. Thus, weobtain

Pr {S} =n"

i=k+1

Pr {Si} . (5.13)

We now compute Pr {Si}. In order to succeed when the best-qualified applicantis the i th one, two things must happen. First, the best-qualified applicant must bein position i , an event which we denote by Bi . Second, the algorithm must notselect any of the applicants in positions k +1 through i "1, which happens only if,for each j such that k + 1 $ j $ i " 1, we find that score( j) < bestscore in line 6.(Because scores are unique, we can ignore the possibility of score( j) = bestscore.)In other words, it must be the case that all of the values score(k + 1) throughscore(i "1) are less than M(k); if any are greater than M(k) we will instead returnthe index of the first one that is greater. We use Oi to denote the event that noneof the applicants in position k + 1 through i " 1 are chosen. Fortunately, thetwo events Bi and Oi are independent. The event Oi depends only on the relative

=

参考用の人数を何人にすればよいか

最初のk人の中に最高得点者がいる場合、成功しない。

(Bi:最高の応募者がi番目に出現)∩(Oi:  k+1からi-­‐1番目の応募者が不採用)

この二つの条件が成り立てばよい

=

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

n全員が最高得点者になる確率を等分に持っている

p109-­‐110

Page 7: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  7

2010年CS勉強会 アルゴリズムイントロダクション

最良の人を雇用する確率

–   i =  k+1,•••,n    

5.4 Probabilistic analysis and further uses of indicator random variables 115

then rejecting the first k applicants, and hiring the first applicant thereafter who hasa higher score than all preceding applicants. If it turns out that the best-qualifiedapplicant was among the first k interviewed, then we will hire the nth applicant.This strategy is formalized in the procedure ON-LINE-MAXIMUM(k, n), whichappears below. Procedure ON-LINE-MAXIMUM returns the index of the candidatewe wish to hire.

ON-LINE-MAXIMUM(k, n)

1 bestscore ! "#2 for i ! 1 to k3 do if score(i) > bestscore4 then bestscore ! score(i)5 for i ! k + 1 to n6 do if score(i) > bestscore7 then return i8 return n

We wish to determine, for each possible value of k, the probability that wehire the most qualified applicant. We will then choose the best possible k, andimplement the strategy with that value. For the moment, assume that k is fixed.Let M( j) = max1$i$ j {score(i)} denote the maximum score among applicants 1through j . Let S be the event that we succeed in choosing the best-qualifiedapplicant, and let Si be the event that we succeed when the best-qualified appli-cant is the i th one interviewed. Since the various Si are disjoint, we have thatPr {S} = !n

i=1 Pr {Si}. Noting that we never succeed when the best-qualified ap-plicant is one of the first k, we have that Pr {Si} = 0 for i = 1, 2, . . . , k. Thus, weobtain

Pr {S} =n"

i=k+1

Pr {Si} . (5.13)

We now compute Pr {Si}. In order to succeed when the best-qualified applicantis the i th one, two things must happen. First, the best-qualified applicant must bein position i , an event which we denote by Bi . Second, the algorithm must notselect any of the applicants in positions k +1 through i "1, which happens only if,for each j such that k + 1 $ j $ i " 1, we find that score( j) < bestscore in line 6.(Because scores are unique, we can ignore the possibility of score( j) = bestscore.)In other words, it must be the case that all of the values score(k + 1) throughscore(i "1) are less than M(k); if any are greater than M(k) we will instead returnthe index of the first one that is greater. We use Oi to denote the event that noneof the applicants in position k + 1 through i " 1 are chosen. Fortunately, thetwo events Bi and Oi are independent. The event Oi depends only on the relative

= (Bi:最高の応募者がi番目に出現)∩(Oi:  k+1からi-­‐1番目の応募者が不採用)

=

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

n全員が最高得点者になる確率を等分に持っている

・・・・・

 1              2                                    k k+1        k+2                                                                                                    n          

・・・

i

・・・・・

不採用

i-­‐1番目までの応募者で  最高得点者がこの中

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

・・・・・

1番目

+ + +

2番目 k番目

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

p110

Page 8: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  8

2010年CS勉強会 アルゴリズムイントロダクション

最良の人を雇用する確率

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

5.4 Probabilistic analysis and further uses of indicator random variables 115

then rejecting the first k applicants, and hiring the first applicant thereafter who hasa higher score than all preceding applicants. If it turns out that the best-qualifiedapplicant was among the first k interviewed, then we will hire the nth applicant.This strategy is formalized in the procedure ON-LINE-MAXIMUM(k, n), whichappears below. Procedure ON-LINE-MAXIMUM returns the index of the candidatewe wish to hire.

ON-LINE-MAXIMUM(k, n)

1 bestscore ! "#2 for i ! 1 to k3 do if score(i) > bestscore4 then bestscore ! score(i)5 for i ! k + 1 to n6 do if score(i) > bestscore7 then return i8 return n

We wish to determine, for each possible value of k, the probability that wehire the most qualified applicant. We will then choose the best possible k, andimplement the strategy with that value. For the moment, assume that k is fixed.Let M( j) = max1$i$ j {score(i)} denote the maximum score among applicants 1through j . Let S be the event that we succeed in choosing the best-qualifiedapplicant, and let Si be the event that we succeed when the best-qualified appli-cant is the i th one interviewed. Since the various Si are disjoint, we have thatPr {S} = !n

i=1 Pr {Si}. Noting that we never succeed when the best-qualified ap-plicant is one of the first k, we have that Pr {Si} = 0 for i = 1, 2, . . . , k. Thus, weobtain

Pr {S} =n"

i=k+1

Pr {Si} . (5.13)

We now compute Pr {Si}. In order to succeed when the best-qualified applicantis the i th one, two things must happen. First, the best-qualified applicant must bein position i , an event which we denote by Bi . Second, the algorithm must notselect any of the applicants in positions k +1 through i "1, which happens only if,for each j such that k + 1 $ j $ i " 1, we find that score( j) < bestscore in line 6.(Because scores are unique, we can ignore the possibility of score( j) = bestscore.)In other words, it must be the case that all of the values score(k + 1) throughscore(i "1) are less than M(k); if any are greater than M(k) we will instead returnthe index of the first one that is greater. We use Oi to denote the event that noneof the applicants in position k + 1 through i " 1 are chosen. Fortunately, thetwo events Bi and Oi are independent. The event Oi depends only on the relative

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

i =  k+1,•••,n  

i =  1,2,•••,k  

1/k  +  1/(k+1)  +  1/(k+2)  +  •••  +  1/(n-­‐1)

実際に入れてみるとわかりやすいです

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

積分での挟み撃ちを利用。

今回は、成功確率(最良の人を雇用する確率)を最大にしたい。  Pr{S}に関するkの値をどのようにするのが最適化かをみる。  計算も楽だし、確率の低い方で考えておけば問題ない。

p110-­‐111

Page 9: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  9

2010年CS勉強会 アルゴリズムイントロダクション

   の計算

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

1068 Appendix A Summations

n+1n–1n–2m+2mm –1

f (m)

f (m+1)

f (m+2)

f (n–2)

f (n–1)

f (n)

f (x)

x… … n

… …

(a)

m+1

n+1n–1n–2m+2mm –1

f (m)

f (m+1)

f (m+2)

f (n–2)

f (n–1)

f (n)

f (x)

x… … n

… …

(b)

m+1

Figure A.1 Approximation of!n

k=m f (k) by integrals. The area of each rectangle is shownwithin the rectangle, and the total rectangle area represents the value of the summation. The in-tegral is represented by the shaded area under the curve. By comparing areas in (a), we get" n

m!1 f (x) dx " !nk=m f (k), and then by shifting the rectangles one unit to the right, we get

!nk=m f (k) "

" n+1m f (x) dx in (b).

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

p325

Page 10: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  10

2010年CS勉強会 アルゴリズムイントロダクション

最良の人を雇用する確率

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

5.4 Probabilistic analysis and further uses of indicator random variables 115

then rejecting the first k applicants, and hiring the first applicant thereafter who hasa higher score than all preceding applicants. If it turns out that the best-qualifiedapplicant was among the first k interviewed, then we will hire the nth applicant.This strategy is formalized in the procedure ON-LINE-MAXIMUM(k, n), whichappears below. Procedure ON-LINE-MAXIMUM returns the index of the candidatewe wish to hire.

ON-LINE-MAXIMUM(k, n)

1 bestscore ! "#2 for i ! 1 to k3 do if score(i) > bestscore4 then bestscore ! score(i)5 for i ! k + 1 to n6 do if score(i) > bestscore7 then return i8 return n

We wish to determine, for each possible value of k, the probability that wehire the most qualified applicant. We will then choose the best possible k, andimplement the strategy with that value. For the moment, assume that k is fixed.Let M( j) = max1$i$ j {score(i)} denote the maximum score among applicants 1through j . Let S be the event that we succeed in choosing the best-qualifiedapplicant, and let Si be the event that we succeed when the best-qualified appli-cant is the i th one interviewed. Since the various Si are disjoint, we have thatPr {S} = !n

i=1 Pr {Si}. Noting that we never succeed when the best-qualified ap-plicant is one of the first k, we have that Pr {Si} = 0 for i = 1, 2, . . . , k. Thus, weobtain

Pr {S} =n"

i=k+1

Pr {Si} . (5.13)

We now compute Pr {Si}. In order to succeed when the best-qualified applicantis the i th one, two things must happen. First, the best-qualified applicant must bein position i , an event which we denote by Bi . Second, the algorithm must notselect any of the applicants in positions k +1 through i "1, which happens only if,for each j such that k + 1 $ j $ i " 1, we find that score( j) < bestscore in line 6.(Because scores are unique, we can ignore the possibility of score( j) = bestscore.)In other words, it must be the case that all of the values score(k + 1) throughscore(i "1) are less than M(k); if any are greater than M(k) we will instead returnthe index of the first one that is greater. We use Oi to denote the event that noneof the applicants in position k + 1 through i " 1 are chosen. Fortunately, thetwo events Bi and Oi are independent. The event Oi depends only on the relative

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

i =  k+1,•••,n  

i =  1,2,•••,k  

1/k  +  1/(k+1)  +  1/(k+2)  +  •••  +  1/(n-­‐1)

実際に入れてみるとわかりやすいです

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

積分での挟み撃ちを利用。

今回は、成功確率(最良の人を雇用する確率)を最大にしたい。  Pr{S}に関するkの値をどのようにするのが最適化かをみる。  計算も楽だし、確率の低い方で考えておけば問題ない。

p111

Page 11: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  11

2010年CS勉強会 アルゴリズムイントロダクション

最良の人を雇用する確率

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

5.4 Probabilistic analysis and further uses of indicator random variables 117

Setting this derivative equal to 0, we see that the lower bound on the probabilityis maximized when ln k = ln n ! 1 = ln(n/e) or, equivalently, when k = n/e.Thus, if we implement our strategy with k = n/e, we will succeed in hiring ourbest-qualified applicant with probability at least 1/e.

Exercises

5.4-1How many people must there be in a room before the probability that someonehas the same birthday as you do is at least 1/2? How many people must there bebefore the probability that at least two people have a birthday on July 4 is greaterthan 1/2?

5.4-2Suppose that balls are tossed into b bins. Each toss is independent, and each ballis equally likely to end up in any bin. What is the expected number of ball tossesbefore at least one of the bins contains two balls?

5.4-3 !For the analysis of the birthday paradox, is it important that the birthdays be mutu-ally independent, or is pairwise independence sufficient? Justify your answer.

5.4-4 !How many people should be invited to a party in order to make it likely that thereare three people with the same birthday?

5.4-5 !What is the probability that a k-string over a set of size n is actually a k-permutation? How does this question relate to the birthday paradox?

5.4-6 !Suppose that n balls are tossed into n bins, where each toss is independent and theball is equally likely to end up in any bin. What is the expected number of emptybins? What is the expected number of bins with exactly one ball?

5.4-7 !Sharpen the lower bound on streak length by showing that in n flips of a fair coin,the probability is less than 1/n that no streak longer than lg n!2 lg lg n consecutiveheads occurs.

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

微分

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

この式の値を最大にするkを知りたい。グラフがかければ一発。  グラフかけなくても、微分をして、プラス

からマイナスへ入れ替わる所があればそこが最大値。(上に凸のグラフ)

0になり、微分した式がプラスからマイナスへ入れ替わる時のk

5.4 Probabilistic analysis and further uses of indicator random variables 117

Setting this derivative equal to 0, we see that the lower bound on the probabilityis maximized when ln k = ln n ! 1 = ln(n/e) or, equivalently, when k = n/e.Thus, if we implement our strategy with k = n/e, we will succeed in hiring ourbest-qualified applicant with probability at least 1/e.

Exercises

5.4-1How many people must there be in a room before the probability that someonehas the same birthday as you do is at least 1/2? How many people must there bebefore the probability that at least two people have a birthday on July 4 is greaterthan 1/2?

5.4-2Suppose that balls are tossed into b bins. Each toss is independent, and each ballis equally likely to end up in any bin. What is the expected number of ball tossesbefore at least one of the bins contains two balls?

5.4-3 !For the analysis of the birthday paradox, is it important that the birthdays be mutu-ally independent, or is pairwise independence sufficient? Justify your answer.

5.4-4 !How many people should be invited to a party in order to make it likely that thereare three people with the same birthday?

5.4-5 !What is the probability that a k-string over a set of size n is actually a k-permutation? How does this question relate to the birthday paradox?

5.4-6 !Suppose that n balls are tossed into n bins, where each toss is independent and theball is equally likely to end up in any bin. What is the expected number of emptybins? What is the expected number of bins with exactly one ball?

5.4-7 !Sharpen the lower bound on streak length by showing that in n flips of a fair coin,the probability is less than 1/n that no streak longer than lg n!2 lg lg n consecutiveheads occurs.

これが最良のk!!

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

代入

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

Pr{Smax} = 1/e

[結論]  k=n/e  を用いるのが最良。  その時、最高の応募者を雇用できる確率は少なくとも  1/e    p111

Page 12: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  12

2010年CS勉強会 アルゴリズムイントロダクション

余談(応用)  昨日のTVでの話

•  初めての彼女と結婚するより最良の人と結婚できる方法は?  – 結婚までに付き合える人数を10人とする  – 付き合っている時に返事をする(よりを戻すことは不可)  

初めての彼女と結婚した場合、最良の人を得る確率は1/10  =  0.1

オンライン雇用問題と全く同じ!(n=10)  最初は結婚しないで参考値だけを得て、  それ以上の人が現れたら即結婚!(^^;)

=  10/(2.7182・・・)  ≒  3.679

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

116 Chapter 5 Probabilistic Analysis and Randomized Algorithms

ordering of the values in positions 1 through i ! 1, whereas Bi depends only onwhether the value in position i is greater than the values in all other positions. Theordering of the values in positions 1 through i ! 1 does not affect whether thevalue in position i is greater than all of them, and the value in position i does notaffect the ordering of the values in positions 1 through i ! 1. Thus we can applyequation (C.15) to obtain

Pr {Si} = Pr {Bi " Oi} = Pr {Bi} Pr {Oi} .

The probability Pr {Bi} is clearly 1/n, since the maximum is equally likely to bein any one of the n positions. For event Oi to occur, the maximum value in po-sitions 1 through i ! 1 must be in one of the first k positions, and it is equallylikely to be in any of these i ! 1 positions. Consequently, Pr {Oi } = k/(i ! 1) andPr {Si} = k/(n(i ! 1)). Using equation (5.13), we have

Pr {S} =n!

i=k+1

Pr {Si}

=n!

i=k+1

kn(i ! 1)

= kn

n!

i=k+1

1i ! 1

= kn

n!1!

i=k

1i

.

We approximate by integrals to bound this summation from above and below. Bythe inequalities (A.12), we have" n

k

1x

dx #n!1!

i=k

1i

#" n!1

k!1

1x

dx .

Evaluating these definite integrals gives us the bounds

kn(ln n ! ln k) # Pr {S} # k

n(ln(n ! 1) ! ln(k ! 1)) ,

which provide a rather tight bound for Pr {S}. Because we wish to maximize ourprobability of success, let us focus on choosing the value of k that maximizes thelower bound on Pr {S}. (Besides, the lower-bound expression is easier to maximizethan the upper-bound expression.) Differentiating the expression (k/n)(ln n ! ln k)with respect to k, we obtain

1n(ln n ! ln k ! 1) .

k  =  n/e  

kは整数  k=3    Pr{S}  ≒  0.3611  k=4    Pr{S}  ≒  0.3665    

Page 13: アルゴリズムイントロダクション 第5.4章

Copyright©  2010  tniky1    All  rights  reserved.   Page  13

2010年CS勉強会 アルゴリズムイントロダクション

参考

雇用問題計算用

n k k/n lgn lgk logn-logk Pr{S} 10 1 0.1 2.302585093 0 2.302585093 0.230258509 10 2 0.2 2.302585093 0.693147181 1.609437912 0.321887582 10 3 0.3 2.302585093 1.098612289 1.203972804 0.361191841 10 4 0.4 2.302585093 1.386294361 0.916290732 0.366516293 10 5 0.5 2.302585093 1.609437912 0.693147181 0.34657359 10 6 0.6 2.302585093 1.791759469 0.510825624 0.306495374 10 7 0.7 2.302585093 1.945910149 0.356674944 0.249672461 10 8 0.8 2.302585093 2.079441542 0.223143551 0.178514841 10 9 0.9 2.302585093 2.197224577 0.105360516 0.094824464 10 10 1 2.302585093 2.302585093 0 0