randomized algorithms
play

Randomized Algorithms Lecture 9 September 24, 2013 Sariel (UIUC) - PowerPoint PPT Presentation

CS 573: Algorithms, Fall 2013 Randomized Algorithms Lecture 9 September 24, 2013 Sariel (UIUC) CS573 1 Fall 2013 1 / 32 Part I . Randomized Algorithms . Sariel (UIUC) CS573 2 Fall 2013 2 / 32 Probability - quick review Definitions


  1. CS 573: Algorithms, Fall 2013 Randomized Algorithms Lecture 9 September 24, 2013 Sariel (UIUC) CS573 1 Fall 2013 1 / 32

  2. Part I . Randomized Algorithms . Sariel (UIUC) CS573 2 Fall 2013 2 / 32

  3. Probability - quick review Definitions . Definition (Informal) . Random variable : a function from probability space to I R . Associates value ∀ atomic events in probability space. . . Definition . The conditional probability of X given Y is [ ] Pr ( X = x ) ∩ ( Y = y ) [ � ] Pr X = x � Y = y = . � [ ] Pr Y = y Equivalent to [ ] [ � ] [ ] Pr ( X = x ) ∩ ( Y = y ) = Pr X = x � Y = y ∗ Pr Y = y . � . Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  4. Probability - quick review Definitions . Definition (Informal) . Random variable : a function from probability space to I R . Associates value ∀ atomic events in probability space. . . Definition . The conditional probability of X given Y is [ ] Pr ( X = x ) ∩ ( Y = y ) [ � ] Pr X = x � Y = y = . � [ ] Pr Y = y Equivalent to [ ] [ � ] [ ] Pr ( X = x ) ∩ ( Y = y ) = Pr X = x � Y = y ∗ Pr Y = y . � . Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  5. Probability - quick review Definitions . Definition (Informal) . Random variable : a function from probability space to I R . Associates value ∀ atomic events in probability space. . . Definition . The conditional probability of X given Y is [ ] Pr ( X = x ) ∩ ( Y = y ) [ � ] Pr X = x � Y = y = . � [ ] Pr Y = y Equivalent to [ ] [ � ] [ ] Pr ( X = x ) ∩ ( Y = y ) = Pr X = x � Y = y ∗ Pr Y = y . � . Sariel (UIUC) CS573 3 Fall 2013 3 / 32

  6. Probability - quick review Even more definitions . Definition . The events X = x and Y = y are independent , if Pr[ X = x ∩ Y = y ] = Pr[ X = x ] · Pr[ Y = y ] . ≡ . . Definition . The expectation of a random variable X its average value: [ ] ∑ = x · Pr[ X = x ] , E X x . Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  7. Probability - quick review Even more definitions . Definition . The events X = x and Y = y are independent , if Pr[ X = x ∩ Y = y ] = Pr[ X = x ] · Pr[ Y = y ] . � [ ] ≡ Pr X = x � Y = y = Pr[ X = x ] . � . . Definition . The expectation of a random variable X its average value: [ ] ∑ = x · Pr[ X = x ] , E X x . Sariel (UIUC) CS573 4 Fall 2013 4 / 32

  8. Linearity of expectations . Lemma (Linearity of expectation.) . [ ] [ ] [ ] ∀ random variables X and Y : E X + Y = E X + E Y . . . Proof. . Use definitions, do the math. See notes for details. . Sariel (UIUC) CS573 5 Fall 2013 5 / 32

  9. Probability - quick review Conditional Expectation . Definition . X , Y : random variables. The conditional expectation of X given Y (i.e., you know Y = y ): [ � ] [ � ] [ � ] ∑ X � Y = E X � Y = y = x ∗ Pr X = x � Y = y . E � � � x . E[ X ] is a number. [ � ] f ( y ) = E � Y = y is a function. X � Sariel (UIUC) CS573 6 Fall 2013 6 / 32

  10. Conditional Expectation . Lemma . [ [ � ]] ∀ X , Y (not necessarily independent): E[ X ] = E . E X � Y � . [ [ � ]] [ [ � ]] = E y � Y = y E E X � Y E X � � . Proof. . Use definitions, and do the math. See class notes. . Sariel (UIUC) CS573 7 Fall 2013 7 / 32

  11. Conditional Expectation . Lemma . [ [ � ]] ∀ X , Y (not necessarily independent): E[ X ] = E . E X � Y � . [ [ � ]] [ [ � ]] = E y � Y = y E E X � Y E X � � . Proof. . Use definitions, and do the math. See class notes. . Sariel (UIUC) CS573 7 Fall 2013 7 / 32

  12. Conditional Expectation . Lemma . [ [ � ]] ∀ X , Y (not necessarily independent): E[ X ] = E . E X � Y � . [ [ � ]] [ [ � ]] = E y � Y = y E E X � Y E X � � . Proof. . Use definitions, and do the math. See class notes. . Sariel (UIUC) CS573 7 Fall 2013 7 / 32

  13. Sorting Nuts & Bolts . Problem ( Sorting Nuts and Bolts ) . . Input: Set n nuts + n bolts. 1 . . Every nut have a matching 2 bolt. . . All diff sizes. 3 . . Task: Match nuts to bolts. 4 (In sorted order). . . Restriction: You can only 5 compare a nut to a bolt. . Q: How to match the n nuts 6 to the n bolts quickly? . Sariel (UIUC) CS573 8 Fall 2013 8 / 32

  14. Sorting Nuts & Bolts . Problem ( Sorting Nuts and Bolts ) . . Input: Set n nuts + n bolts. 1 . . Every nut have a matching 2 bolt. . . All diff sizes. 3 . . Task: Match nuts to bolts. 4 (In sorted order). . Restriction: You can only 5 compare a nut to a bolt. . Q: How to match the n nuts 6 to the n bolts quickly? . Sariel (UIUC) CS573 8 Fall 2013 8 / 32

  15. Sorting Nuts & Bolts . Problem ( Sorting Nuts and Bolts ) . . Input: Set n nuts + n bolts. 1 . . Every nut have a matching 2 bolt. . . All diff sizes. 3 . . Task: Match nuts to bolts. 4 (In sorted order). . . Restriction: You can only 5 compare a nut to a bolt. . . Q: How to match the n nuts 6 to the n bolts quickly? . Sariel (UIUC) CS573 8 Fall 2013 8 / 32

  16. Sorting Nuts & Bolts . Problem ( Sorting Nuts and Bolts ) . . Input: Set n nuts + n bolts. 1 . . Every nut have a matching 2 bolt. . . All diff sizes. 3 . . Task: Match nuts to bolts. 4 (In sorted order). . . Restriction: You can only 5 compare a nut to a bolt. . Q: How to match the n nuts 6 to the n bolts quickly? . Sariel (UIUC) CS573 8 Fall 2013 8 / 32

  17. Sorting Nuts & Bolts . Problem ( Sorting Nuts and Bolts ) . . Input: Set n nuts + n bolts. 1 . . Every nut have a matching 2 bolt. . . All diff sizes. 3 . . Task: Match nuts to bolts. 4 (In sorted order). . . Restriction: You can only 5 compare a nut to a bolt. . Q: How to match the n nuts 6 to the n bolts quickly? . Sariel (UIUC) CS573 8 Fall 2013 8 / 32

  18. Sorting nuts & bolts... Algorithm . . Naive algorithm... 1 . . ...better algorithm? 2 Sariel (UIUC) CS573 9 Fall 2013 9 / 32

  19. Sorting nuts & bolts... Algorithm . . Naive algorithm... 1 . . ...better algorithm? 2 Sariel (UIUC) CS573 9 Fall 2013 9 / 32

  20. Sorting nuts & bolts... MatchNutsAndBolts ( N : nuts, B : bolts) Pick a random nut n pivot from N Find its matching bolt b pivot in B B L ← All bolts in B smaller than n pivot N L ← All nuts in N smaller than b pivot B R ← All bolts in B larger than n pivot N R ← All nuts in N larger than b pivot MatchNutsAndBolts ( N R , B R ) MatchNutsAndBolts ( N L , B L ) QuickSort style... Sariel (UIUC) CS573 10 Fall 2013 10 / 32

  21. Sorting nuts & bolts... MatchNutsAndBolts ( N : nuts, B : bolts) Pick a random nut n pivot from N Find its matching bolt b pivot in B B L ← All bolts in B smaller than n pivot N L ← All nuts in N smaller than b pivot B R ← All bolts in B larger than n pivot N R ← All nuts in N larger than b pivot MatchNutsAndBolts ( N R , B R ) MatchNutsAndBolts ( N L , B L ) QuickSort style... Sariel (UIUC) CS573 10 Fall 2013 10 / 32

  22. What is running time for randomized algorithms? Definitions . Definition . RT ( U ) : random variable – running time of the algorithm on input U . . . Definition . Expected running time E[ RT ( U )] for input U . . . Definition . expected running-time of algorithm for input size n : [ ] T ( n ) = max RT ( U ) . U is an input of size n E . Sariel (UIUC) CS573 11 Fall 2013 11 / 32

  23. What is running time for randomized algorithms? Definitions . Definition . RT ( U ) : random variable – running time of the algorithm on input U . . . Definition . Expected running time E[ RT ( U )] for input U . . . Definition . expected running-time of algorithm for input size n : [ ] T ( n ) = max RT ( U ) . U is an input of size n E . Sariel (UIUC) CS573 11 Fall 2013 11 / 32

  24. What is running time for randomized algorithms? Definitions . Definition . RT ( U ) : random variable – running time of the algorithm on input U . . . Definition . Expected running time E[ RT ( U )] for input U . . . Definition . expected running-time of algorithm for input size n : [ ] T ( n ) = max RT ( U ) . U is an input of size n E . Sariel (UIUC) CS573 11 Fall 2013 11 / 32

  25. What is running time for randomized algorithms? More definitions . Definition . rank( x ) : rank of element x ∈ S = number of elements in S smaller or equal to x . . Sariel (UIUC) CS573 12 Fall 2013 12 / 32

  26. Nuts and bolts running time . Theorem . Expected running time MatchNutsAndBolts ( QuickSort ) is T ( n ) = O ( n log n ) . Worst case is O ( n 2 ) . . . Proof. . Pr[rank( n pivot ) = k ] = 1 n . Thus, [ ] T ( n ) = O ( n ) + T ( k − 1) + T ( n − k ) E k =rank( n pivot ) . Sariel (UIUC) CS573 13 Fall 2013 13 / 32

  27. Nuts and bolts running time . Theorem . Expected running time MatchNutsAndBolts ( QuickSort ) is T ( n ) = O ( n log n ) . Worst case is O ( n 2 ) . . . Proof. . Pr[rank( n pivot ) = k ] = 1 n . Thus, [ ] T ( n ) = O ( n ) + T ( k − 1) + T ( n − k ) E k =rank( n pivot ) = O ( n ) + E k [ T ( k − 1) + T ( n − k )] . Sariel (UIUC) CS573 13 Fall 2013 13 / 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend