Radomized Algorithms I, Sprig 08, Departmet of Computer Sciece, Uiversity of Helsiki Homework : Solutios Discussed Jauary 5, 08). Exercise.: Cosider the followig balls-ad-bi game. We start with oe black ball ad oe white ball i a bi. We repeatedly do the followig: choose oe ball from the bi uiformly at radom, ad the put the ball back i the bi with aother ball of the same color. We repeat util there are balls i the bi. Show that the umber of white balls is equally likely to be ay umber betwee ad. Let W be the umber of white balls whe the total umber of balls is. We eed to show that for all we have PrW k) / ), k,...,. We prove this by iductio. The base case is that, i which case the claim is clearly true. Now assume that the claim is true for some. For k,...,, the evet W + k ca take place i two ways: W k ad a black ball is chose. Possible oly if k <.) W k ad a white ball is chose. Possible oly if k >.) First ote that give W the probability of choosig a white ball is W /. Now usig this ad the defiitio of coditioal probability we get the probability of the first case: Prblack W k) Prblack W k)prw k) k ) k ) Note that i the special case k, the above derivatio is ot valid but the resultig formula still gives the right aswer, amely Prblack W ) 0. Similarly we get the probability of the secod case: Prwhite W k ) Prwhite W k )PrW k ) k Agai the formula gives the right asver for the special case k. Sice the two cases are disjoit evets, we get PrW + k) k ) + k ), Thus the claim is also true for + ad by iductio priciple it holds for all. k ). Exercise.5: Suppose that we roll te stadard six-sided dice. What is the probability that their sum will be divisible by, assumig that the rolls are idepedet? First ote that the rolls are mutually idepedet. Let X i be the result of ith roll ad S X i. The sum of the rolls is divisible by if S 0 0 mod ), where S 0 X 0 + S 9. Assume that the results of first 9 rolls are fixed ad their sum is S 9 s 9. Now there is oly oe value of the last die that makes S 0 divisible by, amely X 0 s 9 mod ). Sice each value i {,,...,} has equal probability, the probability
of the evet is /. More formally we have PrS 0 0 mod )) PrX 0 + S 9 0 mod )) Pr X 0 + x,...,x 9 ) {,...,} 9 Pr X 0 + x,...,x 9 ) {,...,} 9 9 9 x i 0 mod ) X,...,X 9 ) x,...,x 9 ) x i 0 mod ) PrX,...,X 9 ) x,...,x 9 )) x,...,x 9 ) {,...,} 9, ) PrX,...,X 9 ) x,...,x 9 )) where we first used the law of total probability ad the used the fact that the rolls are mutually idepedet. ) 3. Exercise.: Suppose that we idepedetly roll two stadard six-sided dice. Let X be the umber that shows o the first die, X the umber o the secod die, ad X the sum of the umber o the two dice. a) What is E[X X is eve]? Usig the liearity of expectatio: E[X X is eve] E[X + X X is eve] E[X X is eve] + E[X X is eve] E[X X is eve] + E[X ] 3 + 4 3 + 3 ) + + + 3 + 4 + 5 + ) 4 + 3 7 b) What is E[X X X ]? c) What is E[X X 9]? E[X X X ] x x PrX x X X ) 7 E[X X 9] x x x d) What is E[X X X k] for k i the rage [,]? x PrX x X 9) x PrX x X 9) PrX 9) x /3 4/3 4 3 + 4 + 5 + ) 4 Usig the liearity of expectatio ad the fact that X ad X have the same distributio: E[X X X k] E[X X k] E[X X k] 0
4. Exercise.: Suppose we flip a coi times to obtai a sequece of flips X,X,...,X. A streak of flips is a cosecutive subsequece of flips that are all the same. For example, if X 3, X 4, ad X 5 are all heads, there is a streak of legth 3 startig at the third flip. If X is also heads, the there is also a streak of legth 4 startig at the third flip.) a) Let be a power of. Show that the expected umber of streaks of legth log + is o). Deote by k log + the legths of the streaks we are cosiderig. Let Y i be a idicator variable which gets value if there is a streak of legth k startig from the ith flip i,..., k + ). Now the total umber of streaks of legth k is S k+ Y i. Usig the liearity of expectatio ad the fact that E[Y i ] PrY i ), the expectatio of S is k+ E[S] k+ E[Y i ] PrY i ). For Y i to be true, X i ca be either heads or tails but the ext k flips must be the same as X i. Assumig that the flips are idepedet ad the coi is fair, the probability that this happes is PrY i ) /) k. By isertig this to the above equatio we get E[S] k+ ) k which is o) with respect to. k+ ) log k+ k log, b) Show that, for sufficiet large, the probability that there is o streak of legth at least log log log is less tha /. Hit: Break the sequece of flips up ito disjoit blocks of log log log cosecutive flips, ad use that the evet that oe block is a streak is idepedet of the evet that ay other block is a streak.) Let s use otatio k log log log. We break the sequece ito disjoit blocks of k cosecutive flips. There are /k such blocks we igore possible extra flips). For the sequece of flips to ot cotai a streak of k flips deote this evet by A) it is ecessary that oe of the blocks cotais a streak of legth k deote this evet by B). Thus we have PrA) PrB). The probability that a sigle block does ot cotai a streak is /) k. Sice the blocks are disjoit ad thus idepedet), the probability that oe of the blocks cotais a streak is PrB) ) ) k /k Now, sice k log log log ad /k /log, we get ) ) log log log /log PrB) log ) /log exp log )) /log exp log )) exp log log log where the secod iequality is based o the fact that x e x. Let g) log /. Sice g4) 3/4 > /log e ad sice g) is icreasig for > 4 as the derivative Dg)) log /l)) > 0 whe 4), for 4 we have that g) /log e ad therefore )), 3
PrB) exp log ) exp l) log e. 5. Exercise.: A permutatio π : [,] [,] ca be repseted as a set of cycles as follows. Let there be oe vertex for each umber i, i,...,. If the permutatio maps the umber i to the umber πi), the a directed arc is draw from vertex i to vertex πi). This leads to a graph that is a set of disjoit cycles. Notice that some of the cycles could be self-loops. What is the expected umber of cycles i a radom permutatio of umbers? Let X k i be a idicator variable which is if vertex i belogs to a cycle of legth k. Let Y k X k +X k +...+ X k be the total umber of odes belogig to a k-cycle ad let N k be the umber of k-cycles i the graph. By defiitio we must have N k Y k /k. Fially, let N be the total umber of cycles i the graph, which is N k N k. How may permutatios π are there such that Xi k? If vertex i belogs to a k-cycle, the the ext vertex j πi) ca ot be vertex i, vertex π j) ca be either i or j, ad so o, util the k:th vertex is agai i. Thus, we ca choose the cosecutive k vertices o the same cycle i ) ) k + ) ways. The remaiig k vertices ca be i ay order i π, so the umber of possibilities is k) k ). The total umber of permutatios such that Xi k therefore )!. As there are! permutatios i total, the probability of such evet is PrXi k ) )!/! /. Now, by usig the liearity of expectatios twice, we ca get the expecter umber or cycles E[N] k E[N k ] k k E[Y k] k k E[Xi k ] k k k k H).. Exercise.4: We roll a stadard fair die over ad over. What is the expected umber of rolls util the first pair of cosecutive sixes appears? Hit: The aswer is ot 3.) We partitio the roll sequece ito cosecutive subsequeces such that each subsequece begis where the previous subsequece eds, cotiues util the first six is ecoutered, the cotais oe extra roll more ad eds. For example, a sequece,4,,4,3,,,,,) cosists of three such subsequeces:,4),,4,3,,) ad,,). The first pair of cosecutive sixes appears whe, for the first time, the last roll of a subsequece is six. Let N be the umber subsequeces eeded before this happes. Let E i deote the evet that last roll of ith subsequece is six. For ay sigle subsequece the probability of this evet is PE i ) /. Clearly evets E i are idepedet, ad thus N is geometrically distributed with parameter / ad its expectatio is E[N]. Now, let X i be the legth of ith subsequece. The total umber of rolls util the first pair of cosecutive sixes appears is the X N X i. By first usig Lemma.5 ad liearity of expectatios, we get E[X] PrN )E[X N ] PrN )E [ X i ] PrN ) E[X i ]. O the other had, we have X i Y i +, where Y i is the umber of rolls eeded util the first six is ecoutered i ith subsequece. Sice the rolls are idepedet ad the probability of gettig six is / for each roll, Y i is geometrically distributed with parameter /. Thus, we have E[Y i ] ad furthermore E[X i ] + 7. Pluggig that ito the above equatio, we get E[X] PrN ) 7 7 PrN ) 7 E[N] 7 4. 4
Aother way to approach this is to use the memorylessess property. Let X be the umber of rolls util the first pair of cosecutive sixes appears ad let A i deote the evet that ith roll is six. Evets A i are mutually idepedet ad we have PrA i ) /. Now, sice at least two rolls is always required, we ca split up the expectatio as follows: E[X] PrĀ )E[X Ā ] + PrA )E[X A ] PrĀ )E[X Ā ] + PrA ) PrĀ A )E[X A,Ā ] + PrA A )E[X A,A ] ) PrĀ )E[X Ā ] + PrA ) PrĀ )E[X A,Ā ] + PrA )E[X A,A ] ) 5 E[X Ā ] + 5 E[X A,Ā ] + ) E[X A,A ]. Now, as the past rolls do ot have ay effect o the future, if our previous roll is ot six, the the expected umber of additioal rolls we eed is the same as the expected umber of rolls i the begiig. That is, we have E[X A c ] +E[X] ad E[X A,A c ] +E[X]. Also, we have E[X A,A ], sice if A ad A are true, the we already have two cosecutive sixes. Hece, we have E[X] 5 + E[X]) + 5 + E[X]) + ) 35 4 E[X] + 3 3 E[X] 4. 7. Exercise.3: You eed a ew staff assistat, ad you have people to review. You wat to hire the best cadidate for the positio. Whe you iterview a cadidate, you ca give them a score, with the highest score beig the best ad o ties beig possible. You iterview the cadidates oe by oe. Because of your compay s hirig practices, after you iterview the kth cadidate, you either offer the cadidate the job before the ext iterview or you forever lose the chace to hire that cadidate. We suppose the cadidates are iterviewed i a radom order, chose uiformly at radom from all! possible orderigs. We cosider the followig strategy. First, iterview m cadidates but reject them all; these cadidates give you a idea of how strog the field is. After the mth cadidate, hire the first cadidate you iterview who is better tha all of the previous cadidates you have iterviewed. a) Let E be the evet that we hire the best assistat, ad let E i be the evet that ith cadidate is the best ad we hire him. Determie PrE i ), ad show that PrE) m jm+ j. Sice the the order of cadidates is chose uiformly at radom, for the best cadidate each positio is equally likely. Thus, the probability that ith cadidate is the best is /. Now assume, that ith cadidate is the best oe. If i m, the the ith caditate ca ot be hired ad PrE i ) 0. Otherwise, the ith cadidate is hired if ad oly if oe of the cadidates m +,m +,...,i is better tha the best of the first m cadidates, i other words, if the best of the first i cadidates is oe of the first m cadidates. Sice each positio is equally likely, the probability that this happes is m/i ). Therefore we have: PrE i ) { m i if i > m 0 if i m. Now, E E i ad evets E i are disjoit, so the probability of E is PrE) PrE i ) im+ m i m im+ i. b) Boud jm+ j to obtai m l lm) PrE) m l ) lm )). 5
We use the same method as i Lemma.0 to boud the probability PrE). I geeral, if f k) is mootiically decreasig, the b+ b f x)dx f k) f x)dx. a a b ka Hece, by settig f i) /i ), we get a lower boud m + dx m+ x m l lm) ad a upper boud m dx m x m l ) lm )). c) Show that ml lm)/ is maximized whe m /e, ad explai why this meas PrE) /e for this choise of m. We fid the maximum of a fuctio f m) ml lm)/ by fidig where its derivative is zero: f m) l lm 0 lm l m /e To check that this actually is a maximum poit, we calculate the secod derivative: f m) m. This is egative for all m, > 0, so f is cocave w.r.t. m ad thus m /e is a actual maximum poit. By pluggig m /e ito the lower boud iequatio we get PrE) e l l e ) e.