Matroids
Matroids
Matroids
Greedy Algorithms
In this lecture we will examine a couple of famous greedy algorithms and
then look at matroids, which are a class of structures that can be solved by
greedy algorithms.
1
Kruskal’s Algorithm
Let’s take a look at a classic graph problem. A graph G = (V, E) is a
collection of vertices (or ”nodes”) V with a set of edges E. Now suppose
that we have a cost function c : E → R+ that maps each edge to a positive
real number. We now want to find the minimum-cost subgraph (or subset of
edges) that contains a path between any two vertices.
Before we find such a solution, what is the structure of such a subgraph?
Such a subgraph has no cycles. Removing an edge of a cycle maintains at
least one path between any two vertices. Such an acyclic subgraph that visits
all vertices is a spanning tree.
How many edges will such a subgraph have?
Claim: If a connected graph has n vertices, then any spanning tree has
n − 1 edges.
Claim: Any connected graph with n vertices and n − 1 edges is a tree.
Now we will show how to find the minimum spanning tree.
Now we must determine if this will work. Before we can do that, we need
to define a cut. A cut of a graph G = (V, E) is a partition of G’s vertices
into at least two sets.
Figure 2: Example Cut: The left side of the graph is the set S, and the right
side of the graph is all of the vertices except S (or V \S). The cut consists
of the 4 edges between the two components of the graph.
2
Lemma: For any cut, consider any minimum weight edge e in the cut.
Then there is some minimum spanning tree that contains e. (Note that our
wording considers the possibility that there are many edges in the cut that
have the same minimum weight.)
Proof Take an MST T on G. Suppose that there is a cut in G such that
e has minimum weight among edges in the cut but e 6∈ T . Now consider the
cycle induced by T ∪ {e}. (Exercise: Why does adding an edge to a spanning
tree induce a cycle?) Now remove any edge f of this cycle that is in the
same cut. The edge e has weight less than or equal to the weight of f . Then
T 0 = T ∪ {e}\{f } has weight less than or equal to T , so T 0 is also an MST.
3
Theorem: Prim’s algorithm yields an MST. The proof is based on the cut
property discussed earlier.
Matroids
So when do greedy algorithms work? First, let’s describe an abstract struc-
ture called a matroid.
Matroid: A matroid consists of a base set U and a collection I of independent
subsets. Independence will be related to different objects depending on the
problem - for the minimum spanning tree, an independent subset could be a
tree. In linear algebra, an independent subset could be linearly independent
vectors. A matroid’s notion of independence is as follows. A, B ⊆ U satisfy:
A ⊆ B, B ∈ I ⇒ A ∈ I
X = {x1 , x2 , . . . , xn }, x1 ≥ x2 ≥ . . . ≥ xn
,
but the truly optimal solution is:
Y = {y1 , y2 , . . . , yn }, y1 ≥ y2 ≥ . . . ≥ yn
.
Now suppose that k is the earliest index such that xk < yk .
4
Then |{x1 , . . . xk−1 }| < |{y1 , . . . yk }|, and both sets are independent. By
the second property of matroids, there is some yj that can be added to
{x1 , ..., xk−1 } maintaining independence. We know that w(yj ) > w(yk ) be-
cause j < k, and w(yk ) > w(xk ) by assumption. This means that yj would
have been chosen by the greedy algorithm earlier than xk . This is a contra-
diction, so the greedy algorithm must find the optimal solution.
(As an exercise, you may want to show that all maximum weight inde-
pendent sets have the same cardinality (i.e., number of elements). You can
use a small modification of the previous argument to show that this is true.)
Finally, not every greedy algorithm is associated with a matroid, but ma-
troids do give an easy way to construct greedy algorithms for many problems.
Relevant Readings
• Kleinberg and Tardos, Algorithm Design, Chapter 4 (Greedy Algo-
rithms). This book has an excellent treatment of greedy algorithms. It
is highly recommended and is on reserve at the library.
• http://compgeom.cs.uiuc.edu/˜jeffe/teaching/algorithms/notes/04d-matroids.pdf
(The tilde (˜) may have to be retyped if you cut and paste this link.)