Folioby Interconnected
Log InSign Up

Matroids and the Greedy Algorithm

The axioms of a matroid, the graphic matroid, the optimality theorem for the greedy algorithm, a reinterpretation of MST algorithms, and matroid intersection.

FO
Folio Official
March 1, 2026

1 Definition of a Matroid

Definition 1 (Matroid).
A matroid is a pair M=(E,I) consisting of a finite set E and a collection I⊆2E of subsets satisfying three axioms:
  1. (I1) Nonemptiness:∅∈I.

  2. (I2) Hereditary property: If I∈I and J⊆I, then J∈I.

  3. (I3) Augmentation property: If I,J∈I and ∣I∣<∣J∣, then there exists e∈J∖I such that I∪{e}∈I.

The elements of I are called independent sets.
Remark 2.
The augmentation property (I3) abstracts the following fact from linear algebra: if dim(span(I))<dim(span(J)), then J contains a vector that can be added to I while preserving linear independence.

2 The Graphic Matroid

Definition 3 (Graphic matroid).
For a graph G=(V,E), the graphic matroid (or cycle matroid) is M(G)=(E,I), where I={F⊆E∣(V,F) is acyclic}.
Theorem 4.
M(G) is a matroid.
Proof.
(I1): The empty edge set (V,∅) has no cycles, so ∅∈I.

(I2): If F is acyclic and F′⊆F, then F′ is also acyclic. Heredity holds.

(I3): Let I,J∈I with ∣I∣<∣J∣. The subgraph (V,I) is a forest with ∣I∣ edges and ∣V∣−∣I∣ connected components. Similarly, (V,J) has ∣V∣−∣J∣ components. Since ∣V∣−∣J∣<∣V∣−∣I∣, the forest (V,J) has fewer components than (V,I).

It follows by the pigeonhole principle that some edge e∈J∖I connects two vertices that lie in different components of (V,I). Adding e to I does not create a cycle, so I∪{e}∈I. □
Definition 5 (Rank function).
For a matroid M=(E,I), the rank of a subset S⊆E is
r(S)=max{∣I∣∣I⊆S,I∈I}.
The quantity r(E) is the rank of M. For the graphic matroid, r(E)=∣V∣−c, where c is the number of connected components.

3 Optimality of the Greedy Algorithm

Definition 6 (Optimization over a matroid).
Given a matroid M=(E,I) and a weight function w:E→R≥0​, the goal is to find a basis (maximal independent set) that maximizes (or minimizes) w(I)=∑e∈I​w(e).
Theorem 7 (Optimality of the greedy algorithm (Rado, 1957; Edmonds, 1971)).
Let M=(E,I) be a matroid and w:E→R≥0​ a weight function. Sort the elements of E in nonincreasing order of weight: w(e1​)≥w(e2​)≥⋯≥w(em​). The greedy algorithm
I0​=∅,Ik​={Ik−1​∪{ek​}Ik−1​​if Ik−1​∪{ek​}∈I,otherwise,​
produces an independent set Im​ with w(Im​)=max{w(I)∣I∈I}.
Proof.
Let I∗∈I be a maximum-weight independent set, and suppose Im​ is not optimal. Denote the elements chosen by the greedy algorithm as a1​,a2​,…,ar​ (with w(a1​)≥⋯≥w(ar​)), and list the elements of I∗ in nonincreasing weight order as b1​,b2​,…,bs​.

Let j be the first index with w(aj​)<w(bj​) (if no such index exists, then w(Im​)≥w(I∗)). Set J={b1​,…,bj​} and I={a1​,…,aj−1​}. Then ∣I∣<∣J∣ and both I,J∈I. By the augmentation property (I3), there exists bk​∈J∖I with I∪{bk​}∈I. Since w(bk​)≥w(bj​)>w(aj​) and bk​ was not among a1​,…,aj−1​, the greedy algorithm should have chosen bk​ before or at step j (as bk​ appears before aj​ in the weight-sorted order and I∪{bk​} is independent). This contradicts the behavior of the greedy algorithm. □

4 The Converse

Theorem 8 (Characterization of matroids by the greedy algorithm).
Let E be a finite set and I a hereditary family with ∅∈I. If the greedy algorithm produces an optimal solution for every weight function w:E→R≥0​, then (E,I) is a matroid.
Proof.
We prove the contrapositive. Suppose (E,I) is not a matroid, i.e., the augmentation property (I3) fails. Then there exist I,J∈I with ∣I∣<∣J∣ such that I∪{e}∈/I for every e∈J∖I.

Define the weight function: w(e)=1+ε for e∈I, w(e)=1 for e∈J∖I, and w(e)=0 otherwise, where ε>0 is sufficiently small. The greedy algorithm selects the elements of I first (they have the largest weights), after which no element of J∖I can be added. This gives w(Im​)≤∣I∣(1+ε). On the other hand, w(J)=∣I∩J∣(1+ε)+∣J∖I∣≥∣J∣>∣I∣(1+ε) for sufficiently small ε. The greedy algorithm is therefore not optimal. □

5 Kruskal's Algorithm Revisited

Remark 9.
Given a connected graph G=(V,E) with positive edge weights w:E→R>0​, Kruskal's algorithm for finding a minimum spanning tree (MST) sorts the edges in nondecreasing weight order and greedily adds each edge that does not create a cycle.

This is precisely the greedy algorithm on the graphic matroid M(G), optimizing the weight function w′=−w (equivalently, sorting in nondecreasing order corresponds to maximizing the negative weight, i.e., minimizing the original weight). The optimality theorem for the greedy algorithm therefore provides a clean proof that Kruskal's algorithm correctly computes the MST.
graph TD
    A["Matroid (E, I)"] --> B["Graphic Matroid"]
    A --> C["Linear Matroid"]
    A --> D["Uniform Matroid"]
    B --> E["Kruskal = Greedy"]
    C --> F["Linear Independence"]
    E --> G["MST"]

6 Matroid Intersection

Definition 10 (Matroid intersection).
Given two matroids M1​=(E,I1​) and M2​=(E,I2​) on the same ground set E, the matroid intersection problem asks for a largest set belonging to I1​∩I2​.
Theorem 11 (Matroid intersection theorem (Edmonds, 1970)).
max{∣I∣∣I∈I1​∩I2​}=S⊆Emin​(r1​(S)+r2​(E∖S)),
where r1​ and r2​ are the rank functions of M1​ and M2​, respectively.
Remark 12.
Matroid intersection provides a unifying framework for many combinatorial optimization problems, including bipartite matching (which arises as the intersection of two partition matroids) and arborescences. The intersection of two matroids is solvable in polynomial time, but the intersection of three or more matroids is NP-hard in general. Matroid intersection thus marks a sharp boundary between tractability and intractability in combinatorial optimization.
Graph TheoryDiscrete MathematicsTextbookMatroidsGreedy AlgorithmMinimum Spanning Trees
FO
Folio Official

Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.

1 followers·107 articles
Graph Theory TextbookPart 13 of 13
Previous
Introduction to Algebraic Graph Theory
No next article

Share your expertise with the world

Write articles with LaTeX support, build your audience, and earn from your knowledge.

Start Writing — It's Free

More from Folio Official

Folio Official·March 1, 2026

Paths and Connectivity

We formalize the notions of walks, paths, and cycles, then develop the theory of connected components, vertex and edge connectivity, cut vertices and bridges, the characterization of bipartite graphs, and Menger's theorem.

Graph TheoryDiscrete MathematicsTextbook
3
Folio Official·March 1, 2026

Eulerian and Hamiltonian Graphs: Two Classical Traversal Problems

From the Bridges of Königsberg to Euler's theorem on Eulerian circuits, directed Eulerian graphs, Hamiltonian cycles, the theorems of Ore and Dirac, and the NP-completeness of the Hamiltonian cycle problem.

Graph TheoryDiscrete MathematicsTextbook
1
Folio Official·March 1, 2026

Network Flows

Flow networks, the max-flow min-cut theorem, the Ford--Fulkerson method, the Edmonds--Karp algorithm, Dinic's algorithm, and the reduction of bipartite matching to maximum flow.

Graph TheoryDiscrete MathematicsTextbook
Folio Official·March 1, 2026

Why does the greedy algorithm work for trees? — What matroids reveal

Kruskal's algorithm for minimum spanning trees is absurdly simple: sort the edges by weight and add the cheapest one that does not create a cycle. Why does this greedy strategy produce an optimal solution? The answer lies in the cut property and, more deeply, in matroids.

Graph TheoryMathematicsBetween the Lines