
14
Chapter ! Introduction: Some Representative Problems
We will see shortly that this problem can be solved by a very natural
algorithm that orders the set of requests according to a certain heuristic and
then "greedily" processes them in one pass, selecting as large a compatible
subset as it can. This will be .typical of a class of
greedy algorithms
that we
will consider for various problems--myopic rules that process the input one
piece at a time with no apparent look-ahead. When a greedy algorithm can be
shown to find an optimal solution for al! instances of a problem, it’s often fairly
surprising. We typically learn something about the structure of the underlying
problem from the fact that such a simple approach can be optimal.
Weighted Interval Scheduling
In the Interval Scheduling Problem, we sohght to maximize the
number
of
requests that could be accommodated simultaneously. Now, suppose more
generally that each request interval i has an associated
value,
or
weight,
vi > O; we could picture this as the amount of money we will make from
the
i
th
individual if we schedule his or her request. Our goal will be to find a
compatible subset of intervals of maximum total value.
The case in which vi = I for each i is simply the basic Interval Scheduling
Problem; but the appearance of arbitrary values changes the nature of the
maximization problem quite a bit. Consider, for example, that if v
1
exceeds
the sum of all other vi, then the optimal solution must include interval 1
regardless of the configuration of the fi~l set of intervals. So any algorithm
for this problem must be very sensitive to the values, and yet degenerate to a
method for solving (unweighted) interval scheduling when all the values are
equal to 1.
There appears to be no simple greedy rule that walks through the intervals
one at a time, making the correct decision in the presence of arbitrary values.
Instead, we employ a technique,
dynamic programming,
that builds up the
optimal value over all possible solutions in a compact, tabular way that leads
to a very efficient algorithm.
Bipal~te Matching
When we considered the Stable Matching Problem, we defined a
matching
to
be a set of ordered pairs of men and women with the property that each man
and each woman belong to at most one of the ordered pairs. We then defined
a perfect matching to be a matching in which every man and every woman
belong to some pair.
We can express these concepts more generally in terms of graphs, and in
order to do this it is useful to define the notion of a
bipartite graph.
We say that
a graph G ---- (V, E) is
bipa~te
if its node set V can be partitioned into sets X
1.2 Five Representative Problems
and Y in such a way that every edge has one end in X and the other end in Y.
A bipartite graph is pictured in Figure 1.5; often, when we want to emphasize
a graph’s "bipartiteness," we will draw it this way, with the nodes in X and
Y in two parallel columns. But notice, for example, that the two graphs in
Figure 1.3 are also bipartite.
Now, in the problem of finding a stable matching, matchings were built
from pairs of men and women. In the case of bipartite graphs, the edges are
pairs of nodes, so we say that a matching in a graph G = (V, E) is a set of edges
M _c E with the property that each node appears in at most one edge of M.
M is a perfect matching if every node appears in exactly one edge of M.
To see that this does capture the same notion we encountered in the Stable
Matching Problem, consider a bipartite graph G’ with a set X of n men, a set Y
of n women, and an edge from every node in X to every node in Y. Then the
matchings and perfect matchings in G’ are precisely the matchings and perfect
matchings among the set of men and women.
In the Stable Matching Problem, we added preferences to this picture. Here,
we do not consider preferences; but the nature of the problem in arbitrary
bipartite graphs adds a different source of complexity: there is not necessarily
an edge from every x ~ X to every y ~ Y, so the set of possible matchings has
quite a complicated structure. In other words, it is as though only certain pairs
of men and women are willing to be paired off, and we want to figure out
how to pair off many people in a way that is consistent with this. Consider,
for example, the bipartite graph G in Figure 1.5: there are many matchings in
G, but there is only one perfect matching. (Do you see it?)
Matchings in bipartite graphs can model situations in which objects are
being
assigned
to other objects. Thus, the nodes in X can represent jobs, the
nodes in Y can represent machines, and an edge (x~, y]) can indicate that
machine y] is capable of processing job xi. A perfect matching is then a way
of assigning each job to a machine that can process it, with the property that
each machine is assigned exactly one job. In the spring, computer science
departments across the country are often seen pondering a bipartite graph in
which X is the set of professors in the department, Y is the set of offered
courses, and an edge (xi, yj) indicates that professor x~ is capable of teaching
course y]. A perfect matching in this graph consists of an assignment of each
professor to a course that he or she can teach, in such a way that every course
is covered.
Thus the
Bipartite Matching Problem
is the following: Given an arbitrary
bipartite graph
G,
find a matching of maximum size. If IXI = I YI = n, then there
is a perfect matching if and only if the maximum matching has size n. We will
find that the algorithmic techniques discussed earlier do not seem adequate
15
Figure 1.5 A bipartite graph.