Matroids & Exchange Arguments
The capstone of the greedy module: why and when a greedy algorithm is provably optimal. We recap the two correctness templates — greedy-stays-ahead and the exchange argument — then meet the matroid , an abstraction whose exchange property is the structure greedy needs.
╌╌╌╌
Across this module greedy algorithms have succeeded (activity selection,
Huffman codes, Kruskal's and Prim's spanning trees) and failed, on
the 0/1 knapsack. Each success came with a proof: a guarantee that taking the
locally best option never forecloses the global optimum. This lesson is about the
proofs themselves. First we distill the two arguments every greedy correctness
proof is built from. Then we ask whether a structural
property predicts when greedy will work, before we attempt the proof. There is
one: the matroid. Matroid theory makes precise
why Kruskal is correct and 0/1 knapsack is
not, and reduces is greedy optimal here?
to is this structure a matroid?
Two templates for proving greedy optimal
Every greedy correctness proof in this module is an instance of one of two patterns. They are equivalent in power but differ in mechanics.
This is the activity-selection argument: greedy's -th activity finishes no later than the -th activity of any valid schedule, so greedy always has at least as much room left for future activities and ends up with at least as many.
This is the more common template: it proves the greedy-choice property by showing that whatever an optimal solution does first, we may exchange it for greedy's first choice without harm.1 The two templates differ in direction: stays-ahead pushes greedy forward and shows it never falls behind; exchange pulls an optimum toward greedy and shows the pull never hurts. The exchange argument is the one that generalizes into a theory, because its swap step is literally an axiom of the structure we are about to define.
Matroids
A matroid abstracts the notion of independence
: linear independence of
vectors, acyclicity of edges, freedom to add one more element without breaking a
rule.
The first axiom is mild; most natural notions of independence are closed under taking subsets. The exchange property does the work: a smaller independent set can always be grown by taking some element from any larger one. It forbids getting stuck early with a maximal-but-small independent set while a much larger one exists.
A first consequence of the exchange property is that all bases have the same size.
So rank
is well-defined: every base has exactly elements, exactly as every
basis of a vector space has the same dimension. (Indeed, the columns of a matrix, with
the linearly independent subsets, form the linear matroid; this
is where the vocabulary comes from.)
Because , some (here ) joins keeping it independent, so no maximal independent set is left stranded below the rank.
The matroid–greedy theorem
A weighted matroid attaches a positive weight to each element , with . The natural optimization problem: find a maximum-weight independent set. Since weights are positive and is hereditary, a maximum-weight independent set is always a base. The greedy algorithm is the obvious one: sort by weight descending, add each element if it keeps the set independent.
- 1
- 2sort into nonincreasing order by weight
- 3for each in sorted order do
- 4if thenindependence test
- 5
- 6return
The forward direction is a clean exchange argument; it is worth seeing in full, because it is the abstract skeleton of every concrete greedy proof in this module.
Laid out side by side, greedy's picks and the optimum's, both sorted by weight, make the contradiction visible. They agree on weight up to the first index where greedy falls behind (). The prefix is smaller than , so the exchange property yields an element that keeps independent and is heavier than — which greedy, scanning in weight order, must have reached and accepted before . That is the contradiction.
The single step that does all the work is the exchange property gives an element .
That is the matroid axiom standing in for the ad-hoc swap we constructed
by hand for activity selection. The converse, that a non-matroid hereditary
structure has a weight function defeating greedy, is what makes the matroid the
exact characterization, not merely a sufficient condition: if the exchange
property fails for some , one can place weights under which greedy ends in
the stranded maximal set instead of the heavier .
Examples that are matroids
The graphic matroid. Let be a graph. Take and let be the acyclic edge sets, the forests of . This is a matroid: a subset of a forest is a forest (hereditary), and if forests have , then touches more components, so some edge of joins two trees of without creating a cycle (exchange property). The bases are the spanning forests; for a connected graph, the spanning trees, all of size .
Now run on the graphic matroid with negated edge weights
(maximum-weight independent set becomes minimum-weight spanning tree): sort edges,
add each edge that does not form a cycle. That is Kruskal's algorithm,
exactly: the independence test stays acyclic
is the
union-find
cycle check from the minimum spanning trees
lesson. So Kruskal's correctness is the
Rado–Edmonds theorem instantiated on the graphic matroid.
Edges are accepted in weight order (blue); edge is rejected because and are already connected, so adding it would close the cycle , leaving . The accepted set is a base: a spanning tree.
The uniform / partition matroid. Even simpler: fix and let
, so every set of size at most is
independent. This uniform matroid is plainly hereditary, and the
exchange property is trivial (any larger set has a spare element). Greedy reduces
to pick the heaviest elements,
which is obviously optimal; the matroid
machinery confirms the trivial.
The partition matroid generalizes it: partition
into groups and allow at most elements from group ; independence is
within every group's cap.
Scheduling and assignment constraints of the form no more than of this kind
are partition-matroid constraints, which is why greedy
solves so many of them.
Greedy walks the elements in weight order and admits each unless its group is already at capacity. Here the weight- element is skipped even though heavier elements elsewhere were still being accepted — not because of its weight but because group 2's single slot is already spent. That per-group cap is the independence rule, and the exchange property holds because a set below some cap can always borrow an element from any group where a larger set has room.
Beyond greedy: matroid intersection. A single matroid yields to greedy; the
common independent sets of two matroids over the same ground set do not, in
general. Still, matroid intersection solves the maximum-weight common
independent set in polynomial time by augmenting-path methods (bipartite matching
is a special case). The intersection of three matroids is already NP-hard. So
the matroid is the precise frontier of greedy works
; one step beyond it you need
heavier machinery.
Why 0/1 knapsack and TSP are not matroids
The theorem cuts both ways, and it explains the failures we have already seen.
0/1 knapsack. Recall from the greedy method
lesson that greedy fails on the 0/1 knapsack, and from the
knapsack DP lesson that it
needs dynamic programming. The reason, in matroid language: let be the items
and call a set independent
if its total weight fits in capacity . This is
hereditary: drop items and it still fits. But the exchange property fails.
Take capacity and item sizes giving the independent sets and
. Both fit, and , yet no element of
can join , since . The smaller independent set is
stranded: it cannot grow toward the larger one, which is the exact pattern the
exchange property forbids.
The exchange property is violated; the structure is not a matroid; and by Rado–Edmonds some weighting must defeat greedy, recovering the value/density counterexample from the greedy-method lesson.
Traveling salesman. For the TSP, let be the edge sets that extend to a Hamiltonian tour (or the partial-tour fragments greedy builds). This is not even reliably hereditary, and the exchange property fails badly: a cheap partial path can be a dead end that no edge of a longer, valid fragment can extend without revisiting a vertex or exceeding degree . There is no matroid, so no weighting guarantee, and indeed nearest-neighbor greedy can be made arbitrarily bad. The independence structure simply is not a matroid (and TSP is NP-hard regardless).
The pattern is uniform. When greedy is provably optimal, you can almost always exhibit a matroid behind it. When greedy fails, the exchange property is the axiom that breaks.
Greedoids, submodularity, and the reach of greedy works
The matroid is the exact frontier for the classical greedy algorithm, but the
question when is a greedy-style method provably good?
has answers well past it,
developed since Rado and Edmonds.
Matroid intersection and matroid union. As noted, the common independent sets of two matroids over one ground set no longer yield to plain greedy, yet matroid intersection finds a maximum-weight common independent set in polynomial time by augmenting paths, with bipartite matching and many assignment problems as special cases; the intersection of three matroids is NP-hard.3 So the tractable boundary is precisely two matroids.
Greedoids. Relaxing the hereditary axiom to an accessibility axiom gives the greedoid (Korte & Lovász, 1981), a structure broad enough to include the search order of breadth-first and depth-first trees and Dijkstra/Prim shortest-path growth, all of which are greedy but not matroid-greedy.4 The greedoid explains why those algorithms, too, admit clean exchange-style proofs.
Submodularity: the modern generalization. The deepest extension replaces sets that stay independent
with submodular objective functions — set functions
with diminishing returns, where adding an element to a smaller set helps at least
as much as adding it to a larger one. Nemhauser, Wolsey, and Fisher (1978) proved
that for maximizing a monotone submodular function under a cardinality constraint,
the greedy rule (repeatedly add the element of largest marginal gain) is a
approximation, and Feige (1998) showed no
polynomial-time algorithm beats it unless .5
Submodular greedy now underlies influence maximization,
sensor placement, feature and data selection, and document summarization — a direct
descendant of the exchange argument, generalized from independence to
diminishing returns.
Takeaways
- Every greedy correctness proof is a greedy-stays-ahead induction (greedy's -th partial solution is never behind any rival's) or an exchange argument (transform any optimum into the greedy solution without loss). They are equivalent in power; exchange is the one that abstracts into a theory.
- A matroid is a ground set plus a hereditary family of independent sets satisfying the exchange property: any smaller independent set can absorb some element of any larger one. Maximal independent sets are bases; they all share size , the rank.
- Rado–Edmonds theorem: on a weighted matroid, sorting by weight and greedily keeping independence yields a maximum-weight base, and greedy is optimal on a hereditary structure iff it is a matroid. The proof's one nontrivial step rests on the exchange axiom.
- The graphic matroid (acyclic edge sets) makes Kruskal's MST an exact
instance of matroid-greedy; the uniform / partition matroid captures
at most of each kind
constraints. Matroid intersection is the polynomial-time frontier just beyond single-matroid greedy. - 0/1 knapsack and TSP are not matroids (the exchange property fails), which is the structural reason greedy fails on them and dynamic programming or exact search is required instead.
Footnotes
- CLRS, Ch. 16 — Greedy Algorithms (§16.2): the greedy-choice property and optimal substructure, proved by exchanging an optimal solution's first choice for greedy's. ↩
- CLRS, Ch. 16 — Greedy Algorithms (§16.4): the Rado–Edmonds theorem — greedy returns a maximum-weight independent set exactly when the structure is a matroid; the proof rests on the exchange property. ↩
- Edmonds, J. (1970),
Submodular functions, matroids, and certain polyhedra,
in Combinatorial Structures and Their Applications, 69–87 — the matroid-intersection theorem; two matroids are polynomial, three are NP-hard. ↩ - Korte, B. & Lovász, L. (1981),
Mathematical structures underlying greedy algorithms,
in Fundamentals of Computation Theory, LNCS 117, 205–209 — greedoids, relaxing heredity to accessibility so that BFS/DFS/Dijkstra-style growth becomes greedy-provable. ↩ - Nemhauser, G. L., Wolsey, L. A. & Fisher, M. L. (1978),
An analysis of approximations for maximizing submodular set functions—I,
Mathematical Programming 14, 265–294 — the greedy bound for monotone submodular maximization; matched by the hardness of Feige, U. (1998),A threshold of for approximating set cover,
JACM 45(4), 634–652. ↩
╌╌ END ╌╌