COMS 482: unofficial class blog

Lecture 16: More Network Flow

Posted in Class Notes by Elliott Back on February 28th, 2005.

Ford-Fulkerson Algorithm:

ford_fulkerson(G, s, t, capacity):
    f[e] = 0 for all e
    while there exists an s -> t path in the residual graph
        choose a path p
        f = augment(f, p)
        update residual graph
    Endwhile

augment(f, path):
    c = lowest capacity on path
    for each edge e on path
        if e if a forward edge
            f[e] += c
        if e is a backwards edge
            f[e] -= c
    Endfor

Termination:

Every time we find a path, the flow on s increases by at least 1 each time (assuming integer capacities). There is also a maximum possible flow from s, equal to C = sum( ce ) of e out of s = fout(s). We can find a path at most C times, so the total time = O( C * work to find and update path) = O(m*C).

Application: Bipartite Matching:

A Bipartite Matching is defined as V= X + Y where X & Y = {} and for all edges (a, b) in V, a is in X and b is in Y. Imagine wanting to assign people and tasks. You can create a network flow diagram for this:

Bipartite Matching: Network Flow

Here, we draw an edge between a person and a task iff that person can perform said task. Then, running the flow algorithm will assign 1 person to every task, or find the best possible match. This runs in O(m*n) time, where m is the number of edges and n is the number of vertices.

Lecture 15: Network Flow

Posted in Class Notes by Elliott Back on February 25th, 2005.
  • Source s with outflow only
  • Source t with inflow only
  • Directed graph with non-negative edge capacities

The goal is the minimize the flow from s -> t. A flow is a function f:E -> R+, from the edge set to amount of flow on that edge. We also define ce to be the capacity of an edge e. To be a legal flow:

  1. For each edge, 0 <= f(e) <= ce
  2. For each node v other than s, t, fin(v) = fout(v)

The value of a flow f, v(f) = fin(t) = fout(s) = sum( f(e) ) of eout of s = sum( f(e) ) of ein of t. As you’ve seen by now, fin(v) = sum( f(e) ) of ein of v, and fout(v) = sum( f(e) ) of eout of v.

Here is an example of a network flow diagram:

Network Flow Diagram

Now, imagine pushing 18 units of flow across nodes {s, 1, 3, 4, t} to get the following flow diagram:

Network Flow Diagram

This is bad–it uses up too much of our capacity. The most we can push again from s -> t is only 2! Let’s allow the option of “undoing” an edge:

Residual Graph

This is our redidual graph. Everywhere we have flow, we potentially have:

  1. Some capacity left
  2. Some “backflow” we can use to change our mind

Ford-Fulkerson Algorithm (Overview):

Find an s -> t path in graph
Update all flows
Make a new residual graph
Repeat

Lecture 14: Review

Posted in Class Notes by Elliott Back on February 23rd, 2005.

The following are topics for prelim 1:

  • Stable matching
  • Basic algorithms analysis
  • Graphs
  • Greedy algorithms
  • Divide and conquer
  • Dynamic programming

There will be 1-2 algorithms questions, and then some short answer questions about specific topics (Prim’s, Dijkstra’s).

Lecture 13: Change Detection in Lines

Posted in Class Notes by Elliott Back on February 21st, 2005.

On change detection in sequences of points. Segmented Least Squares with multi-way choices. Read section 6.3 in the book.

Algorithm:

For all pairs (i, j) | i <= j, compute the least squares error ei, j for the segment pi … pj
C is a constant that defines the range of allowable error

For j = 1 to n
    For i = 1 to j
        OPT(j) = min(ei, j + C + OPT(i-1));
    End For
EndFor

Return OPT(n)

Reasoning:

We partition the set of points into the set of all possible line segments. Then, for each line segment we compute the error of a least-squares fit through that line segment. Then, we iterate through all the line segments, finding the last point which has “acceptable” error, otherwise starting a new subsequence. In this way, we choose an optimal number and location of least squares fits for our data.

Prelim 1 Coming!

Posted in Exams by Elliott Back on February 20th, 2005.

We’ve got a prelim on thursday–here are some study tips: www.cs.cornell.edu/courses/cs482/2005sp/review1.htm

Next Page »