Algorithm Search⌘K

Proofs: Matroid greedy algorithm

These are the human proofs of Matroid greedy algorithm, at full length.

The matroid greedy algorithm returns a maximum-weight basis full

This proof shows: correctness, termination.

We use the pseudocode of the page. The input is a matroid M=(E,I)M = (E, \mathcal{I}) with ∣E∣=n|E| = n, given by the test indepindep, and a weight function w:E→Rw : E \to \mathbb{R}. Let e1,…,ene_1, \ldots, e_n be the order of line L1, so w(e1)≥⋯≥w(en)w(e_1) \ge \cdots \ge w(e_n). Let A0=∅A_0 = \emptyset and let AiA_i be the value of AA after iteration ii of the loop of line L3. The algorithm returns AnA_n.

Claim. The algorithm stops after nn oracle calls, and AnA_n is a basis of MM with w(An)≥w(B)w(A_n) \ge w(B) for every basis BB. Moreover, for every independent set XX with elements x1,…,xsx_1, \ldots, x_s sorted so that w(x1)≥⋯≥w(xs)w(x_1) \ge \cdots \ge w(x_s), and for the elements g1,…,grg_1, \ldots, g_r of AnA_n in the order in which they were added, s≤rs \le r and w(gk)≥w(xk)w(g_k) \ge w(x_k) for k=1,…,sk = 1, \ldots, s.

Step 1: termination. The sort of line L1 stops, and the loop of line L3 runs nn times with one oracle call each.

Step 2: AiA_i is independent. A0=∅∈IA_0 = \emptyset \in \mathcal{I} by (I1). If Ai−1A_{i-1} is independent, then AiA_i is either Ai−1A_{i-1} or Ai−1∪{ei}A_{i-1} \cup \{e_i\}, and line L5 runs only when line L4 found Ai−1∪{ei}∈IA_{i-1} \cup \{e_i\} \in \mathcal{I}.

Step 3: AnA_n is a basis. Let x∈E∖Anx \in E \setminus A_n. Then x=eix = e_i for some ii with Ai−1∪{ei}∉IA_{i-1} \cup \{e_i\} \notin \mathcal{I}. Since Ai−1∪{ei}⊆An∪{ei}A_{i-1} \cup \{e_i\} \subseteq A_n \cup \{e_i\}, the hereditary property (I2) gives An∪{x}∉IA_n \cup \{x\} \notin \mathcal{I}. So no element can be added to AnA_n, and AnA_n is a maximal independent set, a basis. Write r=∣An∣r = |A_n|.

Step 4: s≤rs \le r. Let XX be independent. If ∣X∣>r|X| > r, then (I3) applied to AnA_n and XX gives x∈X∖Anx \in X \setminus A_n with An∪{x}∈IA_n \cup \{x\} \in \mathcal{I}, against Step 3. So s=∣X∣≤rs = |X| \le r.

Step 5: w(gk)≥w(xk)w(g_k) \ge w(x_k). The elements g1,…,grg_1, \ldots, g_r were added in the order of line L1, so w(g1)≥⋯≥w(gr)w(g_1) \ge \cdots \ge w(g_r). Suppose that w(gk)<w(xk)w(g_k) < w(x_k) for some k≤sk \le s, and take the least such kk. Let P={g1,…,gk−1}P = \{g_1, \ldots, g_{k-1}\} and Q={x1,…,xk}Q = \{x_1, \ldots, x_k\}. Both are independent by (I2), and ∣P∣=k−1<k=∣Q∣|P| = k - 1 < k = |Q|, so by (I3) there is xj∈Q∖Px_j \in Q \setminus P with P∪{xj}∈IP \cup \{x_j\} \in \mathcal{I}. Since j≤kj \le k, w(xj)≥w(xk)>w(gk)w(x_j) \ge w(x_k) > w(g_k). Let xj=etx_j = e_t. Because w(et)>w(gk)w(e_t) > w(g_k), line L1 puts ete_t before gkg_k. At the start of iteration tt, the set At−1A_{t-1} contains only elements added before gkg_k, so At−1⊆PA_{t-1} \subseteq P, and At−1∪{et}⊆P∪{xj}A_{t-1} \cup \{e_t\} \subseteq P \cup \{x_j\} is independent by (I2). So line L4 accepted ete_t, and et∈Ane_t \in A_n was added before gkg_k, which means et∈Pe_t \in P. This contradicts xj∉Px_j \notin P. So w(gk)≥w(xk)w(g_k) \ge w(x_k) for all k≤sk \le s.

Step 6: optimality. Let BB be any basis. All bases have the same size, so ∣B∣=r|B| = r, and by Step 5 with X=BX = B and s=rs = r,

w(B)=∑k=1rw(xk)≤∑k=1rw(gk)=w(An).w(B) = \sum_{k=1}^{r} w(x_k) \le \sum_{k=1}^{r} w(g_k) = w(A_n).

The argument does not use the sign of the weights. If all weights are nonnegative, Step 5 also gives w(X)≤∑k≤sw(gk)≤w(An)w(X) \le \sum_{k \le s} w(g_k) \le w(A_n) for every independent set XX, so AnA_n is a maximum-weight independent set. ■\blacksquare

Back to Matroid greedy algorithm