MIT 6.1220 — Lecture 18
Randomized Algorithms
Definition (Sublinear). An algorithm is sublinear if it runs in less than 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 of the correct one.
Definition (Decision Approximation). In decision problems, an approximation algorithm should:
Always return Yes for Yes-instances.
Return No with probability if the input is “far” from a Yes-instance.
Otherwise, return either Yes or No. (We don't care.)
Problem. (Diameter) Consider a metric that satisfies the triangle inequality, presented in the form of a symmetric matrix . Output the diameter of , or the maximum entry of .
Find an approximation algorithm that runs in , where is the size of the input.
Solution. (Diameter) Pick some , and just return . By the triangle inequality, we're off by at most a factor of , and this runs in time.
Problem. (Connectivity) The input is a graph with vertices, each of which has degree at most . Decide whether is connected, as an approximation algorithm.
Remark. Solving this problem exactly requires time. To distinguish the graphs and , one must check edges, which is indeed , as for these graphs.
Solution. (Connectivity) Say an instance is considered far if it is not .
Definition. A graph on vertices and max degree is if one can add fewer than edges to make connected.
Let be a graph that is not -close to connected. Then the following are true.
Claim 1. The graph must have greater than connected components.
Proof: Obviously.
Claim 2. At least half of the connected components must have less than vertices.
Proof: By claim 1, we have a lot of connected components. But we only have vertices.
Claim 3. At least vertices are in connected components with less than vertices.
Proof: Combine claims 1 and 2. Every connected component has at least one vertex.
Our strategy is to run the following process times.
Process. Pick a random vertex . Run BFS on until either is discovered to be in a connected component with less than vertices, or vertices have been visited.
If we “catch” a vertex as being part of a connected component with less than vertices, we declare No.
If is not -close to connected, the probability we discover this is:
And the runtime is , which is sublinear.
Problem. (Sorted) Decide if a list of distinct numbers is sorted.
Remark. The list is a useful counterexample.
The list is another useful counterexample. (There's only inversions!)
Solution. (Sorted) Say an instance is considered far if it is not .
Definition. A list is if one can delete at most elements and get a sorted list.
Our strategy is to run the following process times.
Process. Pick an index uniformly at random. Compute the value . Now binary search for 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 , which is sublinear.
To argue correctness, say an index is good if the binary search for succeeds.
Claim. If and and are both good, then .
Proof: Consider the binary search paths for and .
At some point they diverge; at that point, everything to the left (including ) better be smaller, and everything to the right (including ) better be bigger.
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 -close to sorted, it must have at least elements that are not good.
So our probability of success is at least , yippee.