CSE 200 Computability ad Complexity Wedesday, May 15, 2013 Lecture 14: Radomized Computatio (cot.) Istructor: Professor Shachar Lovett Scribe: Dogcai She 1 Radmized Algorithm Examples 1.1 The k-th Elemet Defiitio 1 (The k-th elemet) Iput: A def = {a 1, a 2,, a } ad k. Goal: Fid the k-th elemet (i the ordered set). (whe k = 2, it s fidig the media). The algorithm with low time complexity was iveted i 1973. But the algorithm was a little ucovetioal: it s a radomized algorithm. Algorithm 1 Elemet(A, k) [3] 1: Choose radom a i A (called pivot). 2: Partitio A to S {a j : a j a i }, ad H {a j : a j > a i }. 3: If S k, retur Elemet(S, k). If S < k, retur Elemet(H, k S ). Claim 2 The expected ruig time of Algorithm 1 is O(). Corollary 3 W.h.p., Algorithm 1 s ruig time is O(). Defiitio 4 (Expected ruig time) Let T (A, k) be the expected ruig time o iputs A ad k. A() def = max A = k [] T (A, k) Proof of Claim 2: {1,, }. We will prove T () c. Let l be the idex of a i i the order. l is uiform i T (A, k) + 1 max(t (l), T ( l)) l=1 + 2 T (l) l= 2 +1 By iductio o, T () + 2 = + 2c = + 2c l= 2 +1 cl [( ) ( + 1 2 + 1 )] 2 2 [ ( + 1) 2 ( 2 + 1) ] 2 2 14-1
= + 2c [ ] 3 2 8 + O() = + 3 c + O(c) 4 c Proof of Corollary 3: E [T ()] c. By Markov s iequality: Pr [T () > 10c] < 1 10. 1.2 Primality testig Defiitio 5 (PRIMALITY) Iput: a iteger. Goal: Is prime or composite? Theorem 6 (Fermat) If is a prime, the 1 a 1, a 1 1 (mod ) Algorithm 2 Miller-Rabi [5, 6] 1: Choose a radom a {1,, 1}. 2: If a 1 1 (mod ), retur NOT PRIME. Let S 1. 3: As log as a 1 1 (mod ), ad S is eve: S S 2. 4: If a S ±1 (mod ), retur PRIME, else retur NOT PRIME. We kow If is prime, Miller-Rabi returs PRIME always. If is composite, Miller-Rabi returs NOT PRIME w.p. 3 4. Before the AKS Algorithm, people foud some determiistic algorithms for PRIMALITY assumig some umber-theoretic cojectures (e.g., Geeralized Riema Hypothesis). The stadard trick to compute powers efficietly. Suppose we wat to compute a b mod. Cosider b s biary represetatio b log b b 1 b 0. Namely, b = b 0 + 2b 1 + 4b 2 + 8b 3 + where b l {0, 1} for ay l [log b]. The, a b = a b0 (a 2 ) b1 (a 4 ) b2. Compute a 2 mod, a 4 mod, a 8 mod,..., i order, ad the compute the multiplicatio, reducig modulo after each step. 1.3 Coectivity i Udirected Graphs Defiitio 7 (UCONN) Iput: a udirected graph G, vertices s, t. Goal: Is s, t i the same compoet? Algorithm 3 Radom walks o udirected graphs 1: Start a radom walk at s. At each step, choose eighbors with equal probability. 2: Stop util t is reached, or the radom walk made too may steps. Oe ca show that if s, t are coected the the expected ruig time of Algorithm 3 is O( 3 ). Hece, we ca set the algorithm to halt ad retur NO after O( 3 ) steps. The beefit of radom walks is it uses little space (O(log )). For example, it s very appealig for samplig pages o the Iteret. Google s Web 14-2
page crawler actually performs radom walks followig liks from a page to aother page. However, radom walks does ot solve the reachability problem i directed graphs i geeral. Cosider Figure 1, it takes the radom walk startig at ode 1 expected O(2 ) steps to reach ode. The reaso is that at each ode i, the walk goes back to its startig poit w. prob. 1 2. This makes the probability of reachig ode after 1 steps 2 ( 1), a expoetially small probability. 1 2 3 4 Figure 1: Radom walks do ot work o directed graphs 1.4 Polyomial idetity testig ad perfect matchig testig Defiitio 8 (Polyomial Idetity Testig) Iput: A real polyomial p(x 1,, x ) of a low degree; efficiet way to evaluate p o iputs. Goal: Is p 0 or ot? A simple method: evaluate the polyomial o a radom assigmet, retur whether it s 0 or ot. Lemma 9 (Schwartz-Zippel) If p(x 1,, x ) is a ozero degree D polyomial, S R, S > D. If choose a 1,, a S are chose uiformly ad idepedetly the Pr [p(a 1,, a ) = 0] D a 1,,a S S Lemma 9 was rediscovered may times i history. It s left as a problem i homework. The iequality is tight meaig that we ca actually costruct a polyomial by iterpolatio ad have correspodig poits to make it equality. A applicatio example for the above polyomial idetity testig is to fid the perfect matchig of a bipartite graph. Cosider a bipartite graph G = (V 1 V 2, E), V 1 = V 2 =. Defiitio 10 (Perfect matchig) A perfectio matchig is a permutatio π S s.t. (1, π(1)), (2, π(2)),, (, π()) E. Idea: Build a matrix A, A i,j def = { x i,j (i, j) E 0 (i, j) E Claim 11 G has a perfect matchig iff det(a) is a ozero polyomial. Proof det(a) = ( 1) sig(π) π S i=1 A i,π(i) = ( 1) sig(π) perfect matchig π i=1 We do t kow a determiistic way to do it. x i,π(i) 14-3
Questio 12 Ca we deradomize polyomial idetity testig? 2 Radomized Complexity Classes Defiitio 13 (Two-sided error algorithm) x L Pr [M(x) = 1] 2/3. x L Pr [M(x) = 1] 1/3. Defiitio 14 (Oe-sided error algorithm) x L Pr [M(x) = 1] 2/3. x L Pr [M(x) = 1] = 0. May atural radomized algorithms are oe-sided. For example, the primality testig ad polyomial idetity testig described above. Defiitio 15 (BPP, RP, co-rp) BPP def = Two-sided error polyomial time. RP def = Oe-sided error polyomial time (x L o error). co-rp def = Same as RP except for o error for x L. ZPP def = Algorithms ruig i expected polyomial time, but always retur correct aswers. Deradomizatio is itimately related to provig lowerbouds (e.g., [4]). Claim 16 ZPP = RP co-rp. Theorem 17 (Adelma [1]) BPP P/poly. Theorem 18 (Sipser-Gács [7]) BPP Σ 2 Π 2. It suffices to prove that BPP Σ 2 for the Sipser-Gács Theorem, sice BPP is closed uder complemet. Proof of Claim 16 (also see [2] Page 141, Exercise 7.6): ( ) Suppose L ZPP, there exists M s.t. M(x) = L(x). Ruig time i expectatio is c. Defie M (x): Ru M(x) for 3 c steps; If it did t halt, retur 0. If x L the M (x) returs 1 with probability 2/3. If x / L the M (x) returs 0 always. Hece L RP. Replacig 0 with 1 would show that also L co-rp. ( ) Suppose L RP co-rp, that is Machie M 1, x L, Pr [M 1 (x) = 1] 2 3 ad x L, Pr [M 1(x) = 0] = 1. Machie M 2, x L, Pr [M 2 (x) = 1] = 1 ad x L, Pr [M 2 (x) = 0] 2 3. Defie M (x) If M 1 (x) = 1, the retur x L. If M 2 (x) = 0, the retur x L. Retry. Say M 1, M 2 ru i c time, x, retur i first 2 lies of code w.p. 2 3. Pr [retry] 1 def 3. Let T = expected ruig time. The, T 2 c + 1 3 T. Hece, T O(c ). We will prove Theorem 17 ad Theorem 18 i the ext class. 14-4
Refereces [1] Leoard M. Adlema. Two theorems o radom polyomial time. I FOCS, pages 75 83, 1978. [2] Sajeev Arora ad Boaz Barak. Computatioal Complexity - A Moder Approach. Cambridge Uiversity Press, 2009. [3] Mauel Blum, Robert W. Floyd, Vaugha R. Pratt, Roald L. Rivest, ad Robert Edre Tarja. Time bouds for selectio. J. Comput. Syst. Sci., 7(4):448 461, 1973. [4] Russell Impagliazzo ad Avi Wigderso. P = BPP if e requires expoetial circuits: Deradomizig the xor lemma. I STOC, pages 220 229, 1997. [5] Gary L. Miller. Riema s hypothesis ad tests for primality. I Proceedigs of seveth aual ACM symposium o Theory of computig, STOC 75, pages 234 239, New York, NY, USA, 1975. ACM. [6] Michael O Rabi. Probabilistic algorithm for testig primality. Joural of Number Theory, 12(1):128 138, 1980. [7] Michael Sipser. A complexity theoretic approach to radomess. I STOC, pages 330 335, 1983. 14-5