BITS Pilani
CS F364: Design and Analysis of Algorithms

Matroids: Greedy Optimization

Lecture 18 |2026-06-11

Greedy on Matroids

  • Greedy on Matroids
  • The Equivalence Theorem
  • Proof: Greedy Works for Matroids
  • Proof: Only Matroids Work for Greedy
  • Summary

Weighted Matroid Optimization

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)

  • Since all bases have the same size, maximizing is equivalent to minimizing with negated weights.
  • The greedy algorithm for this problem is remarkably simple.

Greedy Algorithm on a Matroid

Input: Matroid M = (E, \mathcal{I}), weight function w: E \to \mathbb{R}^+

  1. Sort E by decreasing weight: w(e_1) \ge w(e_2) \ge \dots \ge w(e_m).
  2. Initialize B = \emptyset.
  3. For each e \in E in this order:
    • If B \cup \{e\} \in \mathcal{I}, add e to B.
  4. Return B.

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.)

Example: Greedy on a Graphic Matroid

Consider a graph G = (V,E) with V = \{a,b,c,d\} and edges sorted by decreasing weight:

Graph G
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.

The Equivalence Theorem

  • Greedy on Matroids
  • The Equivalence Theorem
  • Proof: Greedy Works for Matroids
  • Proof: Only Matroids Work for Greedy
  • Summary

Equivalence Theorem

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:

  • (\Leftarrow) If M is a matroid, greedy always finds an optimal basis.
  • (\Rightarrow) If greedy works for all weight functions, M must be a matroid.

Proof: Greedy Works for Matroids

  • Greedy on Matroids
  • The Equivalence Theorem
  • Proof: Greedy Works for Matroids
  • Proof: Only Matroids Work for Greedy
  • Summary

(\Leftarrow) Key Lemma

  • 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|.

(\Leftarrow) Proof of Key Lemma

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. ✓

(\Leftarrow) From Lemma to Optimality

  • Since |B_k| \ge |B^*_k| for all k, and both are bases at the end (|B| = |B^*| = r):

w(B) - w(B^*) = \sum_{i=1}^m w(e_i) \big( [e_i \in B] - [e_i \in B^*] \big)

  • The partial sum up to k counts how many heavy elements greedy has “extra” vs optimal:

\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^*). ◻

(\Leftarrow) Intuition

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.

Proof: Only Matroids Work for Greedy

  • Greedy on Matroids
  • The Equivalence Theorem
  • Proof: Greedy Works for Matroids
  • Proof: Only Matroids Work for Greedy
  • Summary

(\Rightarrow) Proving Hereditary (I1)

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}.

  • Assign w(e) = 1 for e \in Y, w(e) = 0 otherwise.
  • Greedy considers all e \in Y first (highest weight). Since Y \notin \mathcal{I}, greedy must reject some e \in Y when adding it would create a dependency.
  • But Y is a subset of X \in \mathcal{I}, so Y should be independent by (I1). This is a contradiction. ✓

(\Rightarrow) Proving Exchange (I2)

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}

(\Rightarrow) Exchange — Contradiction

Greedy behavior:

  • First picks all of X (weight 1+\epsilon, highest).
  • Then considers elements of Y \setminus X (weight 1). By assumption, none can extend X.
  • Greedy stops with B = X, total weight |X|(1+\epsilon).

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. ◻

Summary

  • Greedy on Matroids
  • The Equivalence Theorem
  • Proof: Greedy Works for Matroids
  • Proof: Only Matroids Work for Greedy
  • Summary

Why Matroids Matter: Greedy vs DP

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

Examples

  • MST (graphic matroid) → greedy works → Kruskal’s / Prim’s O(E \log V)
  • Maximum bipartite matching → intersection of 2 partition matroids → not greedy, needs augmenting paths
  • TSP → no matroid structure → NP-hard, needs approximation

Summary — What We Learned

  • The greedy algorithm finds a maximum-weight independent set iff the structure is a matroid.
  • This unifies many greedy algorithms:
    • Kruskal’s (graphic matroid) — add cheapest non-cycle edge
    • Maximum-weight forest — add heaviest acyclic edge
    • Selection with quotas (partition matroid) — pick best from each category
    • Scheduling with deadlines (certain matroid structures)
  • When constraints form a matroid, greedy is provably optimal.
  • When they don’t, greedy may fail — use DP or other techniques.

The beauty: one abstract theorem proves correctness of an entire family of algorithms.