18.01.2014 Views

Randomized Algorithms

Randomized Algorithms

Randomized Algorithms

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CS 124 Section #7 <strong>Randomized</strong> <strong>Algorithms</strong> 4/7/13<br />

1 Random Walks<br />

A random walk is a path generated by a sequence of random steps. A simple type of random walk is a<br />

one-dimensional random walk, wherein steps take place between integers, you start at 0, and at each step<br />

you either move up one (with probability 1/2) or down one (with probability 1/2).<br />

2-SAT: In lecture, we gave the following randomized algorithm for solving 2-SAT. Start with some truth<br />

assignment, for example by setting all the variables to false. Find some clause that is not yet satisfied.<br />

Randomly choose one the variables in that clause and change its value. Continue this process, stopping<br />

after some specified number of iterations (and stopping earlier if all clauses are satisfied).<br />

We used a random walk with a completely reflecting boundary at 0 to model our randomized solution<br />

to 2-SAT. Fix some solution S and keep track of the number of variables k consistent with the solution<br />

S. In each step, we either increase or decrease k by one. Using this model, we showed that if a solution<br />

exists, we can expect to find it in time n 2 .<br />

Exercise. You decide to go to a casino and gamble. You start with k dollars, and you decide that if you<br />

ever have n ≥ k dollars, you will take your winnings and go home. Assuming that at each step you either<br />

win $1 or lose $1 (with equal probability), what is the probability that you instead lose all your money?<br />

2 Linear programming<br />

1. We have an objective function (to be minimized or maximized) and a set of constraints, all linear in<br />

some variables x 1 , . . . , x n .<br />

2. Geometric visualization:<br />

(a) A linear equation of the form c 1 x 1 + . . . c n x n = c determines a hyperplane in n-dimensional<br />

space.<br />

(b) A constraint c 1 x 1 + . . . c n x n ≤ c (or ≥ c) therefore defines a half-space, which consists of all<br />

points to one side of the hyperplane.<br />

(c) The set of points satisfying all the constraints is given by the intersection of all these half-spaces,<br />

which is a convex polyhedron. (You can think about why it has to be convex.)<br />

1


(d) The objective function, a 1 x 1 +. . .+a n x n , can be thought of as a moveable hyperplane: We want<br />

to find the highest (maximization) or lowest (minimization) value of α such that the hyperplane<br />

a 1 x 1 + . . . + a n x n = α still intersects the polyhedron. Therefore the optimum occurs at a corner<br />

of the polyhedron, which is why the simplex algorithm works.<br />

Exercise. Express the following problem as a linear programming problem: A farmer has 10 acres to plant<br />

in wheat and rye. He has to plant at least 7 acres. He has $1200 to spend; each acre of wheat costs $200<br />

to plant and each acre of rye costs $100 to plant. Moreover, the farmer has to get the planting done in 12<br />

hours, and it takes an hour to plant an acre of wheat and 2 hours to plant an acre of rye. If the profit is<br />

$500 per acre of wheat and $300 per acre of rye, how many acres of each should be planted to maximize<br />

profits?<br />

Exercise. Express the following problem as a linear programming problem: A gold processor has two<br />

sources of gold ore, source A and source B. In order to keep his plant running, at least three tons of ore<br />

must be processed each day. Ore from source A costs $20 per ton to process, and ore from source B costs<br />

$10 per ton to process. Costs must be kept to less than $80 per day. Moreover, Federal Regulations require<br />

that the amount of ore from source B cannot exceed twice the amount of ore from source A. If ore from<br />

source A yields 2 oz. of gold per ton, and ore from source B yields 3 oz. of gold per ton, how many tons of<br />

ore from both sources must be processed each day to maximize the amount of gold extracted subject to the<br />

above constraints?<br />

2


3 Network flows<br />

3.1 Simplex algorithm for network flows<br />

1. Simple example:<br />

S<br />

1<br />

T<br />

2<br />

3<br />

A<br />

Reduction to a linear program: Objective is to maximize f ST + f SA .<br />

(a) Edge constraints: f ST ≤ 1, f SA ≤ 2, f AT ≤ 3, all are ≥ 0.<br />

(b) Conservation of flow: f SA = f AT .<br />

3.2 Max flow / min cut<br />

1. Network: represented by a directed graph whose edge weights are flow capacities and whose vertices<br />

include a start vertex S and an end-vertex T<br />

2. Maximum flow of a network: the maximal flow that can pass from S to T .<br />

3. Minimum cut of a network: a set of nodes containing S but not T , such that the sum of the capacities<br />

of the edges exiting the set is minimized.<br />

4. Maximum flow is equal to minimum cut: Maximum flow ≤ minimum cut is clear. Maximum<br />

flow ≥ minimum cut comes from the augmenting paths algorithm: When there are no more augmenting<br />

paths to be found, all the vertices reachable from S in the residual network form a cut. All<br />

edges crossing this cut must have zero residual capacity, which means the flow is at least the sum of<br />

their original capacities, which in turn is at least the flow of the minimum cut.<br />

5. Residual flow: To form the residual network, we consider all edges e = (u, v) in the graph as well<br />

as the reverse edges ē = (v, u).<br />

(a) Any edge that is not part of the original graph is given capacity 0.<br />

(b) If f(e) denotes the flow going across e, we set f(ē) = −f(e).<br />

(c) The residual capacity of an edge is c(e) − f(e).<br />

In particular, if e is an edge in the original graph with capacity c(e) = c (and with ē not in the<br />

graph), and we ship flow f ≤ c across e, then e has residual capacity c − f. The reverse edge ē then<br />

has residual capacity 0 − (−f) = f.<br />

Exercise. Perform the augmenting paths algorithm on this example, showing the residual graph at each<br />

step. What is the min-cut of this network?<br />

3


A<br />

3<br />

B<br />

1<br />

C<br />

3<br />

3<br />

1 2<br />

S<br />

4<br />

D<br />

5 3<br />

E<br />

T<br />

The augmentation-based max-flow algorithm is called the Ford-Fulkerson method. Ford-Fulkerson doesn’t<br />

specify how augmenting paths are to be found. The BFS-based approach referred to in lecture is known<br />

as Edmonds-Karp and runs in time O(V E 2 ), even for non-integer capacities. In general, the method of<br />

finding augmenting paths affects runtime. In a network with irrational capacities, it is possible to choose<br />

augmenting paths such that Ford-Fulkerson never terminates.<br />

Exercise. Challenge: Give an example of a network for which Ford-Fulkerson does not terminate.<br />

4 LP duality, games<br />

Linear programming problems have the duality property: that is, any LP maximization problem can be<br />

written as a LP minimization problem whose optimum value is the same as that of the maximization<br />

problem’s. (The same is clearly true vice-versa).<br />

We have seen duality in the max-flow/min-cut problem and in matrix games (where the duality result is<br />

called the min-max theorem). To translate from a LP problem to its dual:<br />

1. Transpose the coefficient matrix.<br />

2. Invert maximization to minimization.<br />

3. Switch the RHS and the objective function.<br />

4. Introduce a nonnegative variable for each inequality and an unrestricted one for each equality.<br />

5. For each nonnegative variable introduce a ≥ constraint, and for each unrestricted variable introduce<br />

a = constraint.<br />

4


Exercise. Consider the following zero-sum game, where the entries denote the payoffs of the row player:<br />

( 3 −1<br />

) 2<br />

1 2 −2<br />

Write the column player’s maximization problem as a LP problem. Practice writing the dual LP “mechanically,”<br />

and check the correctness of your answer by writing the row player’s minimization problem as a<br />

LP problem.<br />

Exercise. Now find the equilibrium of this game.<br />

5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!