MIT 6.1220 — Lecture 18

Randomized Algorithms

Definition (Sublinear). An algorithm is sublinear if it runs in less than O(n)O(n) time—less time than it takes to even read the whole input! (Naturally, these are approximation algorithms.)

Definition (Classical Approximation). In classical (e.g. optimization) problems, an approximation algorithm should return an answer within a factor of α\alpha of the correct one.

Definition (Decision Approximation). In decision problems, an approximation algorithm should:

Problem. (Diameter) Consider a metric d:[n]×[n]R0d: [n] \times [n] \to \mathbb{R}^{\geq 0} that satisfies the triangle inequality, presented in the form of a symmetric n×nn \times n matrix DD. Output the diameter of [n][n], or the maximum entry of DD.

Find an approximation algorithm that runs in o(N)o(N), where N=n2N = n^2 is the size of the input.

Solution. (Diameter) Pick some i[n]i \in [n], and just return maxj[n]d(i,j)\max_{j \in [n]} d(i, j). By the triangle inequality, we're off by at most a factor of 22, and this runs in O(n)=o(N)O(n) = o(N) time.   \blacksquare

Problem. (Connectivity) The input is a graph GG with nn vertices, each of which has degree at most dd. Decide whether GG is connected, as an approximation algorithm.

Remark. Solving this problem exactly requires O(nd)O(nd) time. To distinguish the graphs Kn/2Kn/2K_{n/2} \sqcup K_{n/2} and Kn/2,n/2K_{n/2, n/2}, one must check n2×n2=Θ(n2)\frac{n}{2} \times \frac{n}{2} = \Theta(n^2) edges, which is indeed Θ(nd)\Theta(nd), as d=Θ(n)d = \Theta(n) for these graphs.

Solution. (Connectivity) Say an instance is considered far if it is not ϵ-close to connected\underline{\epsilon\text{-close to connected}}.

Definition. A graph GG on nn vertices and max degree dd is ϵ-close to connected\underline{\epsilon\text{-close to connected}} if one can add fewer than ϵnd\epsilon nd edges to make GG connected.

Let GG be a graph that is not ϵ\epsilon-close to connected. Then the following are true.

Claim 1. The graph GG must have greater than ϵdn\epsilon d n connected components.

Proof: Obviously.   \square

Claim 2. At least half of the connected components must have less than 2ϵd\frac{2}{\epsilon d} vertices.

Proof: By claim 1, we have a lot of connected components. But we only have nn vertices.   \square

Claim 3. At least 12ϵdn\frac{1}{2} \epsilon d n vertices are in connected components with less than 2ϵd\frac{2}{\epsilon d} vertices.

Proof: Combine claims 1 and 2. Every connected component has at least one vertex.   \square

Our strategy is to run the following process Cϵd\frac{C}{\epsilon d} times.

Process. Pick a random vertex vv. Run BFS on vv until either vv is discovered to be in a connected component with less than 2ϵd\frac{2}{\epsilon d} vertices, or 2ϵd\frac{2}{\epsilon d} vertices have been visited.

If we “catch” a vertex vv as being part of a connected component with less than 2ϵd\frac{2}{\epsilon d} vertices, we declare No.

If GG is not ϵ\epsilon-close to connected, the probability we discover this is:

Pr[one of the vertices is “caught”]1(112ϵd)C/ϵd>11eC/2.\mathrm{Pr}[\text{one of the vertices is ``caught''}] \geq 1 - \left( 1 - \dfrac{1}{2}\epsilon d \right)^{C/\epsilon d} > 1 - \dfrac{1}{e^{C/2}}.

And the runtime is O(Cϵd2ϵdd)=O(1ϵ2d)O\left(\frac{C}{\epsilon d} \cdot \frac{2}{\epsilon d} \cdot d\right) = O\left(\frac{1}{\epsilon^2 d}\right), which is sublinear.   \blacksquare

Problem. (Sorted) Decide if a list of distinct numbers is sorted.

Remark. The list (1,3,5,,2n1,2,4,6,,2n)(1, 3, 5, \dots, 2n - 1, 2, 4, 6, \dots, 2n) is a useful counterexample.

The list (2,1,4,3,,2n,2n1)(2, 1, 4, 3, \dots, 2n, 2n - 1) is another useful counterexample. (There's only nn inversions!)

Solution. (Sorted) Say an instance is considered far if it is not ϵ-close to sorted\underline{\epsilon\text{-close to sorted}}.

Definition. A list is ϵ-close to sorted\underline{\epsilon\text{-close to sorted}} if one can delete at most ϵn\epsilon n elements and get a sorted list.

Our strategy is to run the following process Cϵ\frac{C}{\epsilon} times.

Process. Pick an index i[n]i \in [n] uniformly at random. Compute the value V=xiV = x_i. Now binary search for VV as if the list were sorted and you didn't know where it was.

If any of these binary searches fails, we declare No. The runtime is O(Cϵlogn)O\left (\frac{C}{\epsilon} \cdot \log n\right ), which is sublinear.

To argue correctness, say an index ii is good if the binary search for xix_i succeeds.

Claim. If i<ji < j and ii and jj are both good, then xi<xjx_i < x_j.

Proof: Consider the binary search paths for xix_i and xjx_j.

At some point they diverge; at that point, everything to the left (including xix_i) better be smaller, and everything to the right (including xjx_j) better be bigger.   \square

The point is that if we remove all elements that are not good, then the remaining list is sorted. Thus, if a list is not ϵ\epsilon-close to sorted, it must have at least ϵn\epsilon n elements that are not good.

So our probability of success is at least 1(1ϵ)C/ϵ1eC1 - \left(1 - \epsilon\right)^{C/\epsilon} \geq 1 - e^{-C}, yippee.   \blacksquare