A matroid is exactly the structure on which the sorted greedy is always optimal. Recognising one is a proof of the greedy for free, and matroid intersection solves a class of problems greedy can’t.
Definition
with:
- ;
- hereditary: subsets of independent sets are independent;
- exchange: if and , some has .
Maximal independent sets (bases) all have the same size, the rank. A minimal dependent set is a circuit.
Proof: all bases have the same size
Let be maximal independent sets (bases) with . By the exchange axiom, some has , contradicting that is maximal (no superset of is independent). So no two bases have , i.e. all bases have equal size.
Rado-Edmonds: for a hereditary family, “sort by weight descending and add if still independent” finds a maximum-weight independent set for every weight function iff the family is a matroid. For a maximum-weight basis with negative weights allowed, keep adding even negative elements; for a maximum-weight independent set, stop at the first negative.
Proof: the matroid greedy is optimal (the "if" direction of Rado–Edmonds)
Let be the greedy output (elements taken in descending weight order, each added iff independence is preserved) and let be any maximum-weight independent set, both indexed in descending weight order (, likewise for ). Claim: for every , and when only non-negative weights are kept (the basis variant drops this restriction). Suppose for contradiction for some smallest such (so for ). Consider and : both independent (prefixes of independent sets stay independent by the hereditary axiom), with . By the exchange axiom, some has independent. Since and is the smallest weight among these (descending order), . But greedy considers elements in descending weight order and had already placed every element of weight before deciding on — in particular it considered (or an equal-weight substitute) no later than step , and since is independent at that point, greedy would have taken some element of weight at or before step rather than — contradicting that greedy’s -th pick has weight exactly (ties broken consistently). So no such exists, proving the claim, and summing over all (restricted to positive weights for the independent-set variant, where greedy correctly stops early) gives ; since was maximum, . (The converse — if greedy is optimal for every weight function then is a matroid — is the harder direction of the classical theorem and is not needed for using the greedy; it is stated here only as the reason “iff” is the correct word.)
Common matroids
| Matroid | Independent sets | Oracle |
|---|---|---|
| uniform | sets of size | count |
| partition | at most from each group | counters |
| graphic | forests | DSU |
| cographic (bond) | edge sets whose removal keeps the graph connected | bridges / DSU on the complement |
| linear | linearly independent vectors (over any field) | Gaussian elimination; XOR basis over |
| transversal | subsets of the left side matchable into the right side | bipartite matching |
| scheduling (unit jobs) | job sets that can all meet their deadlines | sort by deadline, check the -th job has deadline |
| gammoid | sets linked by vertex-disjoint paths to a fixed set | max flow |
Consequences:
- graphic + DSU is Kruskal;
- linear over : “choose numbers with linearly independent XORs maximising total weight”: sort by weight, insert into an XOR basis, keep the ones that insert (XOR Basis);
- scheduling: unit jobs with deadlines and profits, sorted by profit, kept if still feasible (check with a DSU “latest free slot”).
Not matroids: knapsack (weights), matchings in a general graph as edge sets, independent sets of vertices in a graph, paths. If greedy fails on a small example, the structure isn’t a matroid.
Strong basis exchange / bottleneck facts. In a matroid with weights, the greedy basis is simultaneously min-sum and min-max (bottleneck). For MSTs this is “the MST minimises the maximum edge”.
Proof: the min-sum greedy basis is also a min-bottleneck basis
Run greedy for minimum sum by ascending weight (symmetric to the descending-weight version proved above). Let be its output and . Suppose some basis has : then every element of has weight . Let , so (all of except the single element achieving , since greedy’s prefix below any weight threshold is a maximal independent set among elements of smaller weight — if it weren’t maximal, greedy would have added more before reaching ). But is independent, every element of has weight , and ; by the exchange axiom some has independent, with — so greedy, scanning in ascending order, would have added before reaching , making not maximal among weight- elements after all, a contradiction. So no basis has a strictly smaller bottleneck than , and achieves the minimum.
Operations
- Restriction / deletion / contraction keep matroids. Contracting an element in a graphic matroid contracts the edge.
- Dual : bases are complements of bases. The dual of graphic is cographic. .
Proof:
Every basis of is, by definition, the complement of some basis of . All bases of have the same size (proved above), so every basis of has size — and since all bases of also have equal size (it is itself a matroid), that common size is .
- Truncation (keep only sets of size ) and union (sets splittable into one independent set of each) are matroids. The union has rank (Nash-Williams). That gives: edge-disjoint spanning trees exist iff for every partition of the vertices, the number of edges between parts is (Nash-Williams-Tutte).
Matroid intersection
Find a maximum common independent set of two matroids on the same ground set. Greedy fails, but augmenting paths in an exchange graph solve it in oracle calls for the unweighted version, and the weighted version uses shortest augmenting paths with potentials.
Problems that are matroid intersections:
- bipartite matching (two partition matroids), which is why it isn’t a matroid itself;
- rainbow / colourful spanning tree: graphic ∩ partition by colour;
- spanning tree with at most edges of each type;
- arborescences with degree constraints (graphic ∩ partition by head);
- “pick a basis of vectors, at most one from each group”: linear ∩ partition.
Min-max formula: .
Algorithm details and code: Matroid Intersection. Intersection of three matroids is NP-hard (it includes Hamiltonian path), so problems needing three constraints aren’t solved this way.
Recognising a matroid
Ask: “If can’t be added now, can adding more elements ever make it addable?” Then try the exchange axiom on small examples by brute force. If both hold, the greedy is optimal. A quick check is to run the greedy against a brute force on random small instances: a matroid passes every time.