Given a matroid M = (E, \mathcal{I}) with a weight function w: E \to \mathbb{R}^+, find a basis B \in \mathcal{I} of maximum total weight:
\max_{B \in \mathcal{I},\; |B| = \text{rank}(M)} \sum_{e \in B} w(e)
Input: Matroid M = (E, \mathcal{I}), weight function w: E \to \mathbb{R}^+
This is exactly Kruskal’s algorithm when M is the graphic matroid — add the heaviest edge that doesn’t create a cycle. (For MST, negate weights or sort ascending.)
Consider a graph G = (V,E) with V = \{a,b,c,d\} and edges sorted by decreasing weight:
| Step | Edge | w | B \cup \{e\} acyclic? | Action |
|---|---|---|---|---|
| 1 | (b,c) | 9 | Yes (empty + edge) | Add |
| 2 | (a,c) | 7 | Yes (still acyclic) | Add |
| 3 | (a,b) | 5 | No (cycle a-b-c-a) | Skip |
| 4 | (c,d) | 4 | Yes (still acyclic) | Add |
| 5 | (b,d) | 2 | No (cycle b-c-d-b) | Skip |
| 6 | (a,d) | 1 | No (cycle a-c-d-a) | Skip |
Result: B = \{(b,c), (a,c), (c,d)\}, weight = 20 — the maximum spanning tree.
Theorem (Rado 1957, Gale 1968).
The greedy algorithm produces a maximum-weight basis for every weight function w: E \to \mathbb{R}^+ if and only if M = (E, \mathcal{I}) is a matroid.
Matroids characterize exactly the structures where greedy is optimal.
We prove both directions:
The key insight: greedy stays “ahead” of any optimal solution at every prefix.
Sort edges by decreasing weight: w(e_1) \ge w(e_2) \ge \dots \ge w(e_m).
Let B = greedy basis, B^* = optimal basis.
Define B_k = \{e_1,\dots,e_k\} \cap B and B^*_k = \{e_1,\dots,e_k\} \cap B^*.
Lemma
For every k, |B_k| \ge |B^*_k|.
Proof:
Suppose |B^*_k| > |B_k| for some k. Then B_k and B^*_k are both independent, with |B^*_k| > |B_k|.
By (I2), \exists e \in B^*_k \setminus B_k such that B_k \cup \{e\} \in \mathcal{I}.
But e = e_j for some j \le k (it’s among the first k elements).
When greedy considered e_j, B_{j-1} \subseteq B_k, so B_{j-1} \cup \{e_j\} \in \mathcal{I} (by heredity). Greedy would have added it — contradiction. ✓
w(B) - w(B^*) = \sum_{i=1}^m w(e_i) \big( [e_i \in B] - [e_i \in B^*] \big)
\sum_{i=1}^k w(e_i) \big( [e_i \in B] - [e_i \in B^*] \big) = w(B_k) - w(B^*_k)
Since |B_k| \ge |B^*_k| and weights are decreasing, this partial sum is non-negative for every k. Therefore the total w(B) - w(B^*) \ge 0, i.e., w(B) \ge w(B^*). ◻
At every prefix, greedy has at least as many elements as optimal. Since heavier elements come first and greedy picks at least as many of them, its total weight cannot be less.
We show that if either matroid axiom fails, we can construct a weight function where greedy gives a suboptimal result.
Hereditary (I1): Suppose X \in \mathcal{I} but Y \subseteq X is not in \mathcal{I}.
Suppose X, Y \in \mathcal{I} with |Y| > |X|, but no e \in Y \setminus X can extend X. Construct weights:
w(e) = \begin{cases} 1 + \epsilon & e \in X \\ 1 & e \in Y \setminus X \\ 0 & \text{otherwise} \end{cases}
Greedy behavior:
An optimal basis can pick Y, with weight at least |Y| \cdot 1.
For sufficiently small \epsilon (say \epsilon < 1/|X|), |Y| \cdot 1 > |X|(1+\epsilon), contradicting greedy optimality. ✓
Thus M satisfies both (I1) and (I2), so M is a matroid. ◻
The matroid theorem tells us exactly when greedy works:
| If constraints form a … | Greedy is … | Use instead |
|---|---|---|
| Matroid | Always optimal | Greedy ✓ |
| Intersection of 2 matroids | Not guaranteed | Matroid intersection (polynomial) |
| Intersection of 3+ matroids | Not guaranteed | NP-hard in general |
| No matroid structure | Not guaranteed | Dynamic Programming / other |
The beauty: one abstract theorem proves correctness of an entire family of algorithms.
CS F364: Design & Analysis of AlgorithmsTulasimohan Molli