COMPSCI 611: Advanced Algorithms Lecture 5: Matroid Hung Le University of Massachusetts Amherst 01 Sept 2022 Recall: Minimum Spanning Tree I Kruskal: Keep adding the lightest edge as long as it does not creat a cycle. I Proof of correctness: Exchange argument. I Switching an edge of greedy algorithm and an edge of the optimal solution. I Today lecture: generalzing the idea of Kruskal’s algorithm to a more general structure called matroid. Matroid: What is? Matroid A matroid is a pair (S, J ) where S is a set of n elements and J is a collection of subsets of S such that: 1. Non-emptiness: ∅ ∈ J . 2. Heredity: if X ∈ J , then every subset of X belongs to J. 3. Exchange: Any two sets X and Y in J such that |X| < |Y |, then there exists y ∈ Y \ X such that X ∪ {y} ∈ J . Y X y Y X∪ {y} y Examples Matroid A matroid is a pair (S, J ) where S is a set of n elements and J is a collection of subsets of S such that: 1. Non-emptiness: ∅ ∈ J . 2. Heredity: if X ∈ J , then every subset of X belongs to J. 3. Exchange: Any two sets X and Y in J such that |X| < |Y |, then there exists y ∈ Y \ X such that X ∪ {y} ∈ J . I (S, {∅}) is a matroid. I (S, 2S ) is a matroid. 2S is the power set of S. More Examples I ({1, 2, 3}, {∅, {1}, {2}, {3}}) is a matroid. I ({1, 2, 3}, {∅, {2}, {1, 3}}) is NOT a matroid. Independent Set and Basis Let (S, J ) be a matroid I Every subset of S in J is called an independent set. I A subset I ∈ J is a basis if it is NOT a proper subset of another independent set. Example: matroid ({1, 2, 3}, {∅, {1}, {2}, {3}}). I {1} is a basis, ∅ is not a basis. Example: matroid (S, {∅}). I ∅ is a basis. Size of Bases Lemma Any two bases have the same size. Proof: Exchange property I Suppose that there are two bases X and Y s.t. |Y | > |X|. I By the exchange property, there exists y ∈ Y \ X such that X ∪ {y} is an independent set. I As X ⊆ X ∪ {y}, we get a contradiction. (X is a basis if it is NOT a proper subset of another independent set.) Linear Matroid Linear Matroid Let A be an n × n matrix. S = {1, 2, . . . , n} and I ⊆ {1, 2, . . . n} is independent if and only if the coorresponding subset of columns is linearly independent. a11 a A = 21 . . . an1 ... ... .... ... a1n a2n . . . ann (1) Uniform Matroid Uniform Matroid Let k ∈ [0, n] be an integer. S = {1, 2, . . . , n} and I ⊆ {1, 2, . . . n} is independent if and only if |I| ≤ k. Example: I S = {1, 2, 3} and k = 2, then: I Any subset of size at most 2, for example {1} or {1, 2}, is independent. I Bases: {1, 2}, {2, 3}, {1, 3}. Graphic Matroid Graphic Matroid Let G = (V, E) be an undirected graph. S = E and I ⊆ E is independent if (V, I) has no cycle. Verifying matroid properties of Graphic Matroid: I Non-emptiness: ∅ is independent as (V, ∅) has no cycle. I Heredity: if (V, I) is acyclic, so is (V, I 0 ) ∀ I 0 ⊆ I. I Exchange property is more difficult to verify. Exchange Property of Graphic Matroid Graphic Matroid Let G = (V, E) be an undirected graph. S = E and I ⊆ E is independent if (V, I) has no cycle. I Let X, Y be two independent sets such that |X| < |Y |. I (V, X) and (V, Y ) have no cycle. 1 1 2 3 4 6 5 X e 2 6 3 4 Y 5 I Need to show: ∃e ∈ Y \ X such that adding e to (V, X) creates no cycle. Proof of Exchange Property (1) 1 1 2 3 4 6 5 X e 2 6 3 4 Y 5 Lemma ∃ e ∈ Y \ X connecting two different connected components of X. Proof: Let C be any connected component of (V, X), then |Y ∩ E(C)| ≤ |E(C) ∩ X| since E(C) ∩ X induces a spanning tree of vertices in C. I The total number of edges of Y insides all connected components of X is at most |X|. I Since |Y | > |X|, there must be an edge connecting two different connected components of X. Proof of Exchange Property (2) 1 1 2 3 4 6 5 X e 2 6 3 4 Y 5 Lemma ∃ e ∈ Y \ X connecting two different connected components of X. I Let e ∈ Y \ X be an edge in the lemma. I By the lemma, adding e to (V, X) creates no cycle. I Thus, X ∪ {e} is an independent set. Basis of Graphic Matroid Graphic Matroid Let G = (V, E) be an undirected graph. S = E and I ⊆ E is independent if (V, I) has no cycle. Question: What is a basis of a graphic matroid? Matroid Optimization Matroid Optimization Problem Let (S, J ) be a matroid, such that for every e ∈ S has a weight w(e) ≥ 0. Find a basis of maximum total weight of the matroid (S, J ). Example: I (S, J ) is a graphic matroid, then the matroid optimization problemm is to find a spanning tree of maximum weight. Greedy Algorithm Idea: repeatedly add to the solution the maximum weight element if it does not destroy independence. GreedyBasis((S, J ), w) 1. sort S in decreasing weights 2. A ← ∅ 3. for each e ∈ S in the sorted order 4. if A ∪ {e} ∈ J 5. A ← A ∪ {e} 6. return A I Let F (n) be the running time to test whether a set I belongs to J or not. Here n = |S|. I Running time of GreedyBasis is O(n log n + F (n)n) Correctness: Exchange Argument I A = {a1 , . . . , ak } greedy solution, sortedy decreasingly. I O = {o1 , . . . , ok } optimal solution, sorted decreasingly. Since O is optimal: w(o1 ) + . . . + w(ok ) > w(a1 ) + . . . + w(ak ) (2) Let i be smallest index such that w(oi ) > w(ai ). Let Ai−1 = {a1 , . . . , ai−1 } Oi = {o1 , . . . , oi−1 , oi } (3) As |Oi | > |Ai−1 |, there exists o ∈ Oi \ Ai−1 such that {Ai−1 } ∪ {o} is independent by the exchange property. I But w(o) ≥ w(oi ) > w(ai ), the greedy algorithm will choose o instead of ai to add to A, a contradiction. Greedy for non-matroid If (S, J ) is not a matroid, then the greedy algorithm does not produce an optimal solution. A counter example: I Let X, Y be subsets of S s.t. |X| < |Y | and that ∀ y ∈ Y , X ∪ {y} 6∈ J . I Let |X| = m, and assign w(x) = m + 2 for every x ∈ X. I For every y ∈ Y \ X, assign w(y) = m + 1. I For all z ∈ S \ (X ∪ Y ) has w(z) = 0. The greedy algorithm will produce X, but w(X) = m(m + 2) = m2 + 2m. The optimal solution is Y that has w(Y ) ≥ (m + 1)(m + 1) = m2 + 2m + 1 > w(X).