randomization
play

Randomization Algorithm Theory WS 2012/13 Fabian Kuhn Randomization - PowerPoint PPT Presentation

Chapter 6 Randomization Algorithm Theory WS 2012/13 Fabian Kuhn Randomization Randomized Algorithm: An algorithm that uses (or can use) random coin flips in order to make decisions We will see: randomization can be a powerful tool to Make


  1. Chapter 6 Randomization Algorithm Theory WS 2012/13 Fabian Kuhn

  2. Randomization Randomized Algorithm: • An algorithm that uses (or can use) random coin flips in order to make decisions We will see: randomization can be a powerful tool to • Make algorithms faster • Make algorithms simpler • Make the analysis simpler – Sometimes it’s also the opposite… • Allow to solve problems (efficiently) that cannot be solved (efficiently) without randomization – True in some computational models (e.g., for distributed algorithms) – Not clear in the standard sequential model Algorithm Theory, WS 2012/13 Fabian Kuhn 2

  3. Contention Resolution A simple starter example (from distributed computing) • Allows to introduce important concepts • … and to repeat some basic probability theory Setting: • � processes, 1 resource (e.g., shared database, communication channel, …) • There are time slots 1,2,3, … • In each time slot, only one client can access the resource • All clients need to regularly access the resource • If client � tries to access the resource in slot � : – Successful iff no other client tries to access the resource in slot � Algorithm Theory, WS 2012/13 Fabian Kuhn 3

  4. Algorithm Algorithm Ideas: • Accessing the resource deterministically seems hard – need to make sure that processes access the resource at different times – or at least: often only a single process tries to access the resource • Randomized solution: In each time slot, each process tries with probability � . Analysis: • How large should � be? • How long does it take until some process � succeeds? • How long does it take until all processes succeed? • What are the probabilistic guarantees? Algorithm Theory, WS 2012/13 Fabian Kuhn 4

  5. Analysis Events: • � �,� : process � tries to access the resource in time slot � – Complementary event: � �,� ℙ � �,� � �, ℙ � �,� � 1 � � • � �,� : process � is successful in time slot � � �,� � � �,� ∩ � � �,� ��� • Success probability (for process � ) : Algorithm Theory, WS 2012/13 Fabian Kuhn 5

  6. Fixing • ℙ � �,� � � 1 � � ��� is maximized for ��� � � � � ⟹ ℙ � �,� � 1 � 1 � 1 . � • Asymptotics: � ��� For � � 2: 1 1 � 1 � 1 1 � 1 � 1 4 � � � � � 2 • Success probability: �� � ℙ � �,� � � � �� Algorithm Theory, WS 2012/13 Fabian Kuhn 6

  7. Time Until First Success Random Variable � � : • � � � � if proc. � is successful in slot � for the first time • Distribution: • � � is geometrically distributed with parameter ��� � � ℙ � �,� � 1 � 1 � 1 � 1 �� . � • Expected time until first success: � � � � � � � �� Algorithm Theory, WS 2012/13 Fabian Kuhn 7

  8. Time Until First Success Failure Event � �,� : Process � does not succeed in time slots 1, … , � • The events � �,� are independent for different � : � � � ��� 1 � 1 � 1 � 1 ℙ � �,� � ℙ � � �,� � � ℙ � �,� � � ��� ��� • We know that ℙ � �,� � � �� ⁄ : � 1 � 1 � � �� �� � ℙ � �,� � �� Algorithm Theory, WS 2012/13 Fabian Kuhn 8

  9. Time Until First Success No success by time � : ℙ � �,� � � � � �� ⁄ ⁄ � � ���� : ℙ � �,� � � � • Generally if � � Θ��� : constant success probability � � �� ⋅ � ⋅ ln � : ℙ � �,� � � � � ⁄ � � � � �⋅�� � • For success probability 1 � � ⁄ , we need � � Θ�� log �� . � � • We say that � succeeds with high probability in ��� log �� time. Algorithm Theory, WS 2012/13 Fabian Kuhn 9

  10. Time Until All Processes Succeed Event � � : some process has not succeeded by time � � � � � � � �,� ��� Union Bound: For events � � , … , � � , � � ℙ � � � � � ℙ � � � � Probability that not all processes have succeeded by time � : � � � � ℙ � �,� � � ⋅ � �� �� � ℙ � � � ℙ � � �,� . ��� ��� Algorithm Theory, WS 2012/13 Fabian Kuhn 10

  11. Time Until All Processes Succeed Claim: With high probability, all processes succeed in the first � � log � time slots. Proof: • ℙ � � � � ⋅ � ��/�� • Set � � ��� ⋅ � � 1 ln �� Remark: Θ � log � time slots are necessary for all processes to succeed with reasonable probability Algorithm Theory, WS 2012/13 Fabian Kuhn 11

  12. Primality Testing Problem: Given a natural number � � 2 , is � a prime number? Simple primality test: if � is even then 1. return � � 2 2. ⁄ for � ≔ 1 to � 2 3. do if 2� � 1 divides � then 4. 5. return false 6. return true • Running time: � � Algorithm Theory, WS 2012/13 Fabian Kuhn 12

  13. A Better Algorithm? • How can we test primality efficiently? • We need a little bit of basic number theory… ∗ , where � is a prime, the only Square Roots of Unity: In � � solutions of the equation � � ≡ 1 �mod �� are � ≡ �1 �mod �� • If we find an � ≢ �1 �mod �� such that � � ≡ 1 �mod �� , we can conclude that � is not a prime. Algorithm Theory, WS 2012/13 Fabian Kuhn 13

  14. Algorithm Idea Claim: Let � � 2 be a prime number such that � � 1 � 2 � � for an ∗ , integer � � 0 and some odd integer � � 3 . Then for all � ∈ � � � � ≡ 1 mod � �� � � � � ≡ �1 mod � for some 0 � � � �. Proof: • Fermat’s Little Theorem: Given a prime number � , ∗ : � ��� ≡ 1 �mod �� ∀� ∈ � � Algorithm Theory, WS 2012/13 Fabian Kuhn 14

  15. Primality Test We have: If � is an odd prime and � � 1 � 2 � � for an integer � � 0 and an odd integer � � 3 . Then for all � ∈ �1, … , � � 1� , � � ≡ 1 mod � �� � � � � ≡ �1 mod � for some 0 � � � �. Idea: If we find an � ∈ �1, … , � � 1� such that � � ≢ 1 mod � ��� � � � � ≢ �1 mod � for all 0 � � � �, we can conclude that � is not a prime. • For every odd composite � � 2 , at least � � ⁄ of all possible � satisfy the above condition • How can we find such a witness � efficiently? Algorithm Theory, WS 2012/13 Fabian Kuhn 15

  16. Miller ‐ Rabin Primality Test • Given a natural number � � 2 , is � a prime number? Miller ‐ Rabin Test: if � is even then return � � 2 1. compute � , � such that � � 1 � 2 � � ; 2. choose � ∈ �2, … , � � 2� uniformly at random; 3. � ≔ � � mod � ; 4. if � � 1 or � � � � 1 then return true; 5. for � ≔ 1 to � � 1 do 6. � ≔ � � mod � ; 7. if � � 1 then return true; 8. 9. return false; Algorithm Theory, WS 2012/13 Fabian Kuhn 16

  17. Analysis Theorem: • If � is prime, the Miller ‐ Rabin test always returns true . • If � is composite, the Miller ‐ Rabin test returns false with probability at least � � ⁄ . Proof: • If � is prime, the test works for all values of � • If � is composite, we need to pick a good witness � Corollary: If the Miller ‐ Rabin test is repeated � times, it fails to detect a composite number � with probability at most 4 �� . Algorithm Theory, WS 2012/13 Fabian Kuhn 17

  18. Running Time Cost of Modular Arithmetic: • Representation of a number � ∈ � � : ��log �� bits • Cost of adding two numbers � � � mod � : • Cost of multiplying two numbers � ⋅ � mod � : – It’s like multiplying degree ��log �� polynomials  use FFT to compute � � � ⋅ � Algorithm Theory, WS 2012/13 Fabian Kuhn 18

  19. Running Time Cost of exponentiation � � mod � : • Can be done using ��log �� multiplications ���� �� � � 2 � • Base ‐ 2 representation of � : � � ∑ ��� • Fast exponentiation: � ≔ 1; 1. for � ≔ �log �� to 0 do 2. � ≔ � � mod � ; 3. if � � � 1 then � ≔ � ⋅ � mod � ; 4. return � ; 5. • Example: � � 22 � 10110 � Algorithm Theory, WS 2012/13 Fabian Kuhn 19

  20. Running Time Theorem: One iteration of the Miller ‐ Rabin test can be implemented with running time � log � � ⋅ log log � ⋅ log log log � . 1. if � is even then return � � 2 compute � , � such that � � 1 � 2 � � ; 2. choose � ∈ �2, … , � � 2� uniformly at random; 3. � ≔ � � mod � ; 4. if � � 1 or � � � � 1 then return true; 5. for � ≔ 1 to � � 1 do 6. � ≔ � � mod � ; 7. if � � 1 then return true; 8. 9. return false; Algorithm Theory, WS 2012/13 Fabian Kuhn 20

Recommend


More recommend