advanced algorithms ii
play

Advanced Algorithms (II) Shanghai Jiao Tong University Chihao Zhang - PowerPoint PPT Presentation

Advanced Algorithms (II) Shanghai Jiao Tong University Chihao Zhang March 9th, 2020 Random Variables Random Variables Recall that a probability space is a tuple ( , , Pr) Random Variables Recall that a probability space is a tuple (


  1. Advanced Algorithms (II) Shanghai Jiao Tong University Chihao Zhang March 9th, 2020

  2. Random Variables

  3. Random Variables Recall that a probability space is a tuple ( Ω , ℱ , Pr)

  4. Random Variables Recall that a probability space is a tuple ( Ω , ℱ , Pr) In this course, we mainly focus on countable Ω

  5. Random Variables Recall that a probability space is a tuple ( Ω , ℱ , Pr) In this course, we mainly focus on countable Ω A random variable is a function X : Ω → ℝ X

  6. Random Variables Recall that a probability space is a tuple ( Ω , ℱ , Pr) In this course, we mainly focus on countable Ω A random variable is a function X : Ω → ℝ X ∑ The expectation E [ X ] = a ⋅ Pr[ X = a ] a ∈Ω :Pr[ X = a ]>0

  7. Linearity of Expectations

  8. Linearity of Expectations For any random variables X 1 , …, X n n E [ X i ] = n n ∑ ∑ E [ X i ] i =1 i =1

  9. Linearity of Expectations For any random variables X 1 , …, X n n E [ X i ] = n n ∑ ∑ E [ X i ] i =1 i =1 E [ X 1 + X 2 ] = ∑ ( a + b ) ⋅ Pr[ X 1 = a , X 2 = b ] a , b = ∑ a ⋅ Pr[ X 1 = a , X 2 = b ] + ∑ b ⋅ Pr[ X 1 = a , X 2 = b ] a , b a , b = ∑ a ⋅ Pr[ X 1 = a ] + ∑ b ⋅ Pr[ X 2 = b ] = E [ X 1 ] + E [ X 2 ] a b

  10. Coupon Collector

  11. Coupon Collector There are coupons to collect… n

  12. Coupon Collector There are coupons to collect… n Each time one coupon is drawn independently uniformly at random

  13. Coupon Collector There are coupons to collect… n Each time one coupon is drawn independently uniformly at random How many times one needs to draw to collect all coupons?

  14. Let be the number of draws between -th distinct X i i coupon to the -th distinct coupon i + 1

  15. Let be the number of draws between -th distinct X i i coupon to the -th distinct coupon i + 1 n − 1 ∑ Number of draws = X := X i i =0

  16. Let be the number of draws between -th distinct X i i coupon to the -th distinct coupon i + 1 n − 1 ∑ Number of draws = X := X i i =0 For any , follows geometric distribution with i X i n − i probability n

  17. Geometric Distribution

  18. Geometric Distribution Let be a random variable following geometric X distribution with probability . p

  19. Geometric Distribution Let be a random variable following geometric X distribution with probability . p Namely, we toss a coin who comes to HEAD with probability , is the number of tosses to see the first p X HEAD.

  20. Geometric Distribution Let be a random variable following geometric X distribution with probability . p Namely, we toss a coin who comes to HEAD with probability , is the number of tosses to see the first p X HEAD. It is not hard to see that E [ X ] = 1 p

  21. Back to Coupon Collector…

  22. Back to Coupon Collector… E [ X ] = E [ X i ] = n − 1 n − 1 ∑ ∑ E [ X i ] i =0 i =0 n − 1 n − i = n n n n − 2 + … + n n ∑ = n + n − 1 + 1 i =0 = n ⋅ H ( n ) → n log n + γ n

  23. Back to Coupon Collector… E [ X ] = E [ X i ] = n − 1 n − 1 ∑ ∑ E [ X i ] i =0 i =0 n − 1 n − i = n n n n − 2 + … + n n ∑ = n + n − 1 + 1 i =0 = n ⋅ H ( n ) → n log n + γ n The constant is called Euler constant γ = 0.577...

  24. Linearity may fail when…

  25. Linearity may fail when… • n = ∞

  26. Linearity may fail when… • n = ∞ St. Petersburg paradox Each stage of the game a fair coin is tossed and a gambler guesses the result. He wins the amount he bet if his guess is correct and lose the money if he is wrong. He bets at the first $1 stage. If he loses, he doubles the money and bets again. The game ends when the gambler wins.

  27. What is the expected money he wins?

  28. What is the expected money he wins? - In stage , he wins with , E [ X i ] = 0 i X i ∞ ∑ - so E [ X i ] = 0 i =1

  29. What is the expected money he wins? - In stage , he wins with , E [ X i ] = 0 i X i ∞ ∑ - so E [ X i ] = 0 i =1 - On the other hand, he eventually wins , $1 E [ X i ] = 1 ≠ ∞ ∞ ∑ ∑ - so ! E [ X i ] i =1 i =1

  30. Linearity may fail when…

  31. Linearity may fail when… • is random n = N

  32. Linearity may fail when… • is random n = N Suppose we draw a number and toss dices N N E [ X N ] N ∑ , what is ? X 1 , …, X N i =1

  33. Each is uniform in , one might expect {1,…,6} X i E [ X i ] = E [ N ] ⋅ E [ X 1 ] = 3.5 × 3.5 = 12.25 N ∑ i =1

  34. Each is uniform in , one might expect {1,…,6} X i E [ X i ] = E [ N ] ⋅ E [ X 1 ] = 3.5 × 3.5 = 12.25 N ∑ i =1 If itself is drawn by tossing a dice and let N X 1 = X 2 = … = X N = N

  35. Each is uniform in , one might expect {1,…,6} X i E [ X i ] = E [ N ] ⋅ E [ X 1 ] = 3.5 × 3.5 = 12.25 N ∑ i =1 If itself is drawn by tossing a dice and let N X 1 = X 2 = … = X N = N Then E [ X i ] = E [ N ⋅ N ] = 15.166.. N ∑ i =1

  36. Wald’s Equation

  37. Wald’s Equation If the variables satisfy

  38. Wald’s Equation If the variables satisfy - and all are independent and finite; N X i - All are identically distributed X i

  39. Wald’s Equation If the variables satisfy - and all are independent and finite; N X i - All are identically distributed X i N E [ X i ] = E [ N ] ⋅ E [ X 1 ] ∑ i =1

  40. Wald’s Equation If the variables satisfy - and all are independent and finite; N X i - All are identically distributed X i N E [ X i ] = E [ N ] ⋅ E [ X 1 ] ∑ i =1 More generally if is a stopping time N

  41. Application: Quick Select

  42. Application: Quick Select Find the -th largest number in an unsorted array k A

  43. Application: Quick Select Find the -th largest number in an unsorted array k A Find ( ) A , k Randomly choose a pivot x ∈ A 1. Partition into such that A − { x } A 1 , A 2 , ∀ y ∈ A 1 , y < x ∀ z ∈ A 2 , z > x 2. If , return | A 1 | = k − 1 x 3. If , return Find ( ) | A 1 | ≥ k A 1 , k 4. return Find ( ) A 2 , k − | A 1 | − 1

  44. The partition step takes time O ( | A | )

  45. The partition step takes time O ( | A | ) What is the total time cost in expectation?

  46. The partition step takes time O ( | A | ) What is the total time cost in expectation? - size of at -th round X i A i E [ X i +1 ∣ X i ] ≤ 3 and X 1 = n 4 X i ∞ ∑ The time cost is X i i =1

  47. E [ X i +1 ∣ X i ] ≤ 3 4 X i 4 E [ X i ] ≤ ( i 4 ) ⟹ E [ X i +1 ] = E [ E [ X i +1 ∣ X i ]] ≤ 3 3 n

  48. E [ X i +1 ∣ X i ] ≤ 3 4 X i 4 E [ X i ] ≤ ( i 4 ) ⟹ E [ X i +1 ] = E [ E [ X i +1 ∣ X i ]] ≤ 3 3 n E [ X i ] = E [ X i ] ∞ n ∑ ∑ i =1 i =1 i − 1 n n i =1 ( 4 ) 3 ∑ ∑ = E [ X i ] ≤ n i =1 = 4 n .

  49. KUW inequality

  50. KUW inequality While analyzing random algorithms, a common recursion is for random T ( n ) = 1 + T ( n − X n ) X n

  51. KUW inequality While analyzing random algorithms, a common recursion is for random T ( n ) = 1 + T ( n − X n ) X n Theorem . (Karp-Upfal-Wigderson Inequality) Assume for every , is an integer for some such that n 0 ≤ X n ≤ n − a a . If for all , where is positive and T ( a ) = 0 E [ X n ] ≥ μ ( n ) n > a μ ( n ) increasing , then E [ T ( n )] ≤ ∫ n 1 μ ( t ) d t a

  52. Application: Expectation of Geometric Variables

  53. Application: Expectation of Geometric Variables T (1) = 1 + T (1 − X 1 ), where E [ X 1 ] = p

  54. Application: Expectation of Geometric Variables T (1) = 1 + T (1 − X 1 ), where E [ X 1 ] = p E [ T (1)] ≤ ∫ 1 p d t = 1 1 Choosing gives μ ( n ) = p p . 0

  55. Application: Rounds of Quick Select

  56. Application: Rounds of Quick Select In our Find ( ) algorithm, we have A , k T ( n ) = 1 + max{ T ( m ), T ( n − m − 1)},

  57. Application: Rounds of Quick Select In our Find ( ) algorithm, we have A , k T ( n ) = 1 + max{ T ( m ), T ( n − m − 1)}, where is in uniformly at random. {1,2,…, n − 1} m

  58. Application: Rounds of Quick Select In our Find ( ) algorithm, we have A , k T ( n ) = 1 + max{ T ( m ), T ( n − m − 1)}, where is in uniformly at random. {1,2,…, n − 1} m μ ( n ) = n We can choose (Why?) 4

  59. Application: Rounds of Quick Select In our Find ( ) algorithm, we have A , k T ( n ) = 1 + max{ T ( m ), T ( n − m − 1)}, where is in uniformly at random. {1,2,…, n − 1} m μ ( n ) = n We can choose (Why?) 4 KUW implies E [ T ( n )] ≤ ∫ n 4 t d t = 4 log n 1

  60. Application: Coupon Collector

  61. Application: Coupon Collector where T ( m ) = 1 + T ( n − X m ) X m ∼ Ber( m / n )

  62. Application: Coupon Collector where T ( m ) = 1 + T ( n − X m ) X m ∼ Ber( m / n ) So we can choose μ ( m ) = ⌈ m ⌉ n

  63. Application: Coupon Collector where T ( m ) = 1 + T ( n − X m ) X m ∼ Ber( m / n ) So we can choose μ ( m ) = ⌈ m ⌉ n KUW implies E [ T ( n )] ≤ ∫ n n ⌈ t ⌉ d t = n ⋅ H n 0

  64. Proof of KUW inequality

Recommend


More recommend