1 / 44

Instructor: Shengyu Zhang

CSC3160: Design and Analysis of Algorithms. Week 4: Randomized Algorithms. Instructor: Shengyu Zhang. Randomized Algorithms. We use randomness in our algorithms. You’ve seen examples in previous courses quick sort : pick a random pivot . We’ll see more in this week. Motivation.

red
Download Presentation

Instructor: Shengyu Zhang

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC3160: Design and Analysis of Algorithms Week 4: Randomized Algorithms Instructor: Shengyu Zhang

  2. Randomized Algorithms • We use randomness in our algorithms. • You’ve seen examples in previous courses • quick sort: pick a random pivot. • We’ll see more in this week.

  3. Motivation • Why randomness? • Faster. • Simpler. • Price: a nonzero error probability • Usually can be controlled to arbitrarily small. • Repeating times drops the error probability to for some constant . • Second part of the lecture.

  4. General references • Randomized Algorithms, Rajeev Motwani and Prabhakar Raghavan, Cambridge University Press, 1995. • Probability and Computing,Michael Mitzenmacher and Eli Upfal, Cambridge University Press, 2005.

  5. Part 1: Examples Example 1: Polynomial Identity Testing

  6. + −   + − Question • Given two polynomials and (by arithmetic circuit), decide whether they are equal. • Arithmetic circuit: polynomial computed: • Question: Given two such circuits, do they compute the same polynomial?

  7. + −   + − Naïve algorithm? polynomial computed: • We can expand the two polynomials and compare their coefficients • But it takes too much time. • Size of the expansion can be exponential in the number of gates. • Can you give such an example?

  8. Key idea • Schwartz-Zippel Lemma. If is a polynomial of total degree over a field , then , • total degree of a monomial • total degree of a polynomial: the max total degree of its monomials. • : pick each from uniformly at random. (Different ’s are picked independently.)

  9. + −   + − 2 3 4 1 6 Few other observations • A polynomial is easy to evaluate on any point by following the circuit. • The (formal) degree of an polynomial is easy to obtain.

  10. Randomized Algorithm On input polynomials and : • Evaluate and by running the circuits on . • if, output “”. else output “”.

  11. Correctness • If , then is always true, so the algorithm outputs . • If : Let . Recall that • we picked , • Lemma. • So w/ prob. only 0.01. • The algorithm outputs w/ prob. .

  12. Catch • One catch is that if the degree is very large, then the evaluated valuecan also be huge. • Thus unaffordable to write down. • Fortunately, a simple trick called “fingerprint” handles this. • Use a little bit of algebra; omitted here. • Questions for the algorithm?

  13. Part 1: Examples Example 2: minimum cut

  14. Min-cut for undirected graphs • Given an undirected graph, a global min-cut is a cut minimizing the number of crossing edges. • Recall: a crossing edge is an edge s.t. and . S V - S

  15. A simple algorithm • We’ll introduce Karger’sContraction Algorithm. • It’s surprisingly simple.

  16. Graph Contraction b a • For an undirected graph and two vertices . • We contract and and form a new graph : • and merge into one vertex • Naturally, the edgedisappears. • Other edges incident to or in G naturally change to edges incident to in . • Now we may have more than one edge between two vertices. But well… that’s fine. We just keep them there. v u e d c b a {u,v} e d c

  17. Karger’s algorithm • forto repeat randomly pick an edge contract and until two vertices are left ← the number of edges between them • Output

  18. Example • See an example on board.

  19. key fact • If we keep contracting a random edge until two vertices are left, then # of edges between them = min cut with prob. . • Thus repeating this times and taking minimumgive the min-cut with high prob.

  20. Why? • One trial finds the min cut with probability for some constant . • If we make trials, then the probability that none of these finds the min cut is at most • Choose makes this error probability .

  21. Analysis of the key fact • Fix a min cut : If we never picked a crossing edge in the algorithm, then ok. • i.e. then finally the number of edges between two last vertices is the correct answer. • Let’s analyze the probability step by step.

  22. Step 1 • In step 1: what’s the prob. that a crossing edge is not picked? • . • : the number of edges of min cut. • Let’s analyze this quantity: • By def of min cut, we know that each vertex has degree at least . • Otherwise the cut is lighter. • Thus • And c ≥c

  23. Step 2 • Similarly, in step 2, • Pr [no crossing edge picked] ≥ • Note that now the number of vertices is . • … • In general, in step , • Pr [no crossing edge picked]

  24. Together • What’s the prob. that all the steps didn’t contract a crossing edge?

  25. Part 1: Examples Example 3. connectivity and 2-SAT by random walk

  26. Random walk on graphs • Graph . • Starting vertex • Each step: • Go to a random neighbor. • Simple but powerful.

  27. Typical questions about random walk • Hitting time: How long it takes to hit a particular vertex? • : Expected time needed to hit , starting from • General graph: • On a line: • Covering time: How long it takes to visit all other vertices (at least once)? • : Expected time needed to visit all other vertices, starting from s. • General graph: . • On a line :.

  28. Connectivity • -Connectivity: Given an undirected graph and two vertices and in it, decide whether there is a path from to in . • BFS can solve it, but needs space. • Here is an algorithm using only space. • Starting from , do random walk steps • If never seen , output NO; otherwise output YES. • Space: , because one only needs to remember the current vertex. • Correctness: Recall that the hitting time for any and any .

  29. Algorithm for 2-SAT • 2SAT: each clause has two variables /negations • Papadimitriou’s Algorithm: • Pick any assignment • Repeat time • If all satisfied, done • Else • Pick any unsatisfied clause • Pick one of the two literals each with ½ probability, and flip the assignment on that variable 0, 1, 0, 1, 0 1

  30. Analysis • 0, 1, 0, 1, 0 • If unsatisfiable: never find a satisfying assignment • If satisfiable: there exists a satisfying assignment • If our initially picked assignment is satisfying, then done. • Otherwise, for any unsatisfied clause, at least one of the two variables is assigned a value different than that in • Randomly picking one of the two variables and flipping its value increases by 1 w.p. ≥ ½.

  31. Analysis (continued) • Consider a line of points, • Point : we’ve assigned variables correctly • “correctly”: the same way as • : we’ve made and thus found a satisfying assignment! • Recall effect of flipping the value of a random variable (in a “bad” clause): increasesby 1 w.p. ≥ ½. … …

  32. Analysis (continued) • Consider a line of points, • Thus the algorithm is actually a random walk on the line of points, with . • Recall hitting time (): • So by repeating this flipping process steps, we’ll reach with high probability. • And thus find , if such a satisfying assignment exists. … …

  33. Part II: Basic analytical tools

  34. Concentration and tail bounds • In many analysis of randomized algorithms, we need to study how concentrated a random variable is close to its mean . • Many times . • Upper bounds of Pr[ deviates from a lot]is called tail bounds.

  35. Markov’s Inequality: when you only know expectation • [Thm] If , then In other words, if , then • Proof. . • Dropping some nonnegative terms always make it smaller.

  36. Moments • Def. The th moment of a random variable is • : variance.

  37. Chebyshev’sInequality: when you also know variance • [Thm] In other words, . • Proof. // Markov on // recall:

  38. Inequality by the th-moment (: even) • [Thm] . • Proof. // is even // Markov on

  39. Chernoff’s Bound • [Thm] Supposeand let . Then where

  40. Some basic applications • One-sided error: Suppose an algorithm for a decision problem has • : no error • : output with probability 1/2 • We want to decrease this ½ to . How? • Run the algorithm times. Output 0 iff all executions answer 0.

  41. Two-sided error • Suppose a randomized algorithm has two-sided error • : output with probability > 2/3 • : output with probability > 2/3 • How? • Run the algorithm steps and take a majority vote.

  42. Using Chernoff’s bound • Run the algorithm times, getting outputs. Suppose they are . • Let • if : w.p., thus . • if : w.p., so .

  43. Recall Chernoff: • If : . • , so . • . • Similar for . • The error prob. decays exponentially with # of trials!

  44. Summary • We showcased several random algorithms. • Simple and fast • We also talked about some basic tail bounds. • Concentration of a random variable around its mean.

More Related