COMS 482: unofficial class blog

Final Review: Chapters 1 to 4

Posted in Exams by Elliott Back on May 14th, 2005.

Stable Matching, Marriage:

Given some sets M = {m1, … , mn} and W = {w1, … , wn} representing men and women, we want to find a perfect stable matching.

  • A matching is a set of ordered pairs in MxW such that every m, w appear at most once.
  • In a perfect matching, each m, w appear exactly once.
  • An instability occurs when there are two pairs (m, w) and (m’, w’) such that m prefers w’ to w, and w’ prefers m to m’.

Gale-Shapely Algorithm:

Initialize all m in M and w in W to free
while there exists free man m who still has a woman w to propose to {
w = m’s highest ranked such woman
if w is free
engage (m, w)
else some pair (m’, w) already exists
if w prefers m to m’
(m, w) become married
m’ becomes free
else
(m’, w) remain married
}

Termination is obvious. Show there are no instabilities by simple contradition. See Lecture 1 for more on Stable Matching / Marriage.

Breadth First Search:

BFS can be used to identify connected components as well as for testing bipartiteness of graphs. If there are no edges joining nodes in the same BFS layer, then the graph must contain an odd length cycle and be non-bipartite. For more about BFS, see lecture 7 on Breadth-First Search.

Greedy Algorithms:

  • Interval Scheduling: Schedule non-overlapping requests to a certain interval, maximizing the size of the compatible set.

    Simply choose requests with the smallest finishing time, and delete all overlapping requests until done. Proof proceeds by “stays ahead” argument.

    See lecture 3 for a proof of optimality.

  • Interval Partitioning: Schedule all intervals across a minimal number of resources so that none of the intervals scheduled to a particular resource overlap. The number of resources needed is at least the maximum depth of the set of intervals.

    Sort the intervals by start times. Assign a label to the first interval. Then, choose the next interval Ii. For every interval Ibad before Ii that overlaps it, remove Ibad’s label from consideration. Then, assign a non-excluded label to Ii, if there is one.

  • Scheduling to Minimize Lateness: Sort by the earliest deadlines and schedule in this order.

    There’s an optimal schedule with no idle time–our algorithm also has no idle time. If there is an inversion in the optimal solution, there di > dj and j is scheduled after i. If we swap i and j, we keep the same lateness, so the greddy algorithm is optimal by an exchange argument.

  • Dijkstra’s Algorithm: Find the shortest path from a given node to all other nodes (Single Source Shortest Path, SSSP):

    Choose a start node s in V
    PQ.put(s, 0)
    While PQ != {}
    (u, d) = PQ.getMin()
    if u is done then continue
    mark u as done (or report (u, d))
    for v adjacent to u do
    PQ.put(v, d + dist(u,v));
    end for
    end while

Greedy MST Problems:

  • Kruskal’s Algorithm:

    Sort edges by cost
    T = {}
    for e in edges do
    if e does not create a cycle then
    add e to T
    endif
    endfor

  • Prim’s Algorithm:

    Choose a start vertex s
    T = {s}
    While there is a vertex not in T do
    choose least cost edge from T to some vertex not in T
    add this edge to T
    endwhile

  • Reverse Delete Algorithm:

    Sort edges by cost, decreasing
    T = E, the edge set
    for e in T do
    if removing e does not disconnect the graph then
    T = T – {e}
    endif
    endfor

All of these MST algorithms can be implemented in O(m log n) time. Lecture 4 contains a proof that Kruskal’s algorithm produces an MST, lecture 5 proves the same for Prim’s algorithm, and lecture 6 carefully proves the time complexity of Kruskal’s algorithm.

Two interesting MST facts:

  • The most expensive edge of a cycle on G is not in any MST
  • The min cost edge between V-S and S, where S is a strict subset of V, is in the MST

Also, make sure you know how union find operates, replacing parent pointers with a pointer to the root on find() operations, and joining trees smaller to larger on union() operations to keep the trees balanced.

Prelim II Next Tuesday

Posted in Exams by Elliott Back on April 10th, 2005.

Prelim II is next Tuesday. The announcement isn’t on the course website yet, but here are review questions from 2000 spring, for the eager:

  1. You are given a graph G = (V, E) with weights we on its edges {e in E}. The weights can be negative or positive. The Zero-­weight-cycle problem is to decide if there is a simple cycle in G so that the sum of the edge weights on this cycle is exactly 0.

    Prove that this problem is NP­complete.

  2. Since the 3­Dimensional Matching problem is NP­complete, it is natural to expect that the corresponding 4­Dimensional Matching problem is at least as hard. Let us define 4­Dimensional Matching as follows. Given sets W , X , Y , and Z, each of size n, and a collection C of ordered 4­tuples of the form (wi , xj, yk, zl), do there exist n 4-­tuples from C so that no two have an element in common?

    Prove that 4­Dimensional Matching is NP­complete.

  3. Some of your friends have recently graduated and started a small company called WebExodus, which they are currently running out of their parents’ garages in Santa Clara. They’re in the process of porting all their software from an old system to a new, revved­up system; and they’re facing the following problem.

    They have a collection of n software applications, {1, 2, . . . , n}, running on their old system; and they’d like to port some of these to the new system. If they move application i to the new system, they expect a net (monetary) benefit of bi >= 0. The different software applications interact with one another; if applications i and j have extensive interaction, then the company will incur an expense if they move one of i or j to the new system but not both — let’s denote this expense by xi,j >= 0.

    So if the situation were really this simple, your friends would just port all n applications, achieving a total benefit of sum(bi . Unfortunately, there’s a problem . . . Due to small but fundamental incompatibilities between the two systems, there’s no way to port application 1 to the new system; it will have to remain on the old system. Nevertheless, it might still pay to port some of the other applications, accruing the associated benefit and incurring the expense of the interaction between applications on different systems.

    So this is the question they pose to you: which of the remaining applications, if any, should be moved? Give a polynomial­ time algorithm to find a set S # {2, 3, . . . , n} for which the sum of the benefits minus the expenses of moving the applications in S to the new system is maximized.

Update:

New review problems have been posted here: www.cs.cornell.edu/courses/cs482/2005sp/review2.htm

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