Theoretical foundations for greedy methods
There is a beautiful theory about greedy algorithms, which we sketch in this section. This theory is useful in determining when the greedy method yields optimal solutions. It involves combinatorial structures known as "matroids." Although this theory does not cover all cases for which a greedy method applies (for example, it does not cover the activity-selection problem of Section 16.1 or the Huffman coding problem of Section 16.3), it does cover many cases of practical interest. Furthermore, this theory is being rapidly developed and extended to cover many more applications; see the notes at the end of this chapter for references.
S is a finite nonempty set.
ℓ is a nonempty family of subsets of S, called the independent subsets of S, such that if B ∈ℓ and A ⊆ B, then A ∈ℓ. We say thatℓ is hereditary if it satisfies this property. Note that the empty set Ø is necessarily a member ofℓ.
If A ∈ℓ, B ∈ℓ, and |A| < |B|, then there is some element x ∈ B - A such that A ∪ {x} ∈ℓ. We say that M satisfies the exchange property.
The word "matroid" is due to Hassler Whitney. He was studying matric matroids, in which the elements of S are the rows of a given matrix and a set of rows is independent if they are linearly independent in the usual sense. It is easy to show that this structure defines a matroid.
As another example of matroids, consider the graphic matroid MG = (SG,ℓG) defined in terms of a given undirected graph G = (V, E) as follows.
The set SG is defined to be E, the set of edges of G.
If A is a subset of E, then A ∈ℓG if and only if A is acyclic. That is, a set of edges A is independent if and only if the subgraph GA = (V, A) forms a forest.
The graphic matroid MG is closely related to the minimum-spanning-tree problem.
Proof : Clearly, SG = E is a finite set. Furthermore,ℓG is hereditary, since a subset of a forest is a forest. Putting it another way, removing edges from an acyclic set of edges cannot create cycles.
Thus, it remains to show that MG satisfies the exchange property. Suppose that GA = (V, A) and GB = (V, B) are forests of G and that |B| >; |A|. That is, A and B are acyclic sets of edges, and B contains more edges than A does.
Proof Suppose to the contrary that A is a maximal independent subset of M and there exists another larger maximal independent subset B of M. Then, the exchange property implies that A is extendible to a larger independent set A ∪ {x} for some x ∈ B - A, contradicting the assumption that A is maximal.
As an illustration of this theorem, consider a graphic matroid MG for a connected, undirected graph G. Every maximal independent subset of MG must be a free tree with exactly |V| - 1 edges that connects all the vertices of G. Such a tree is called a spanning tree of G.
We say that a matroid M = (S,ℓ) is weighted if there is an associated weight function w that assigns a strictly positive weight w(x) to each element x ∈ S. The weight function w extends to subsets of S by summation:
for any A ⊆ S. For example, if we let w(e) denote the length of an edge e in a graphic matroid MG, then w(A) is the total length of the edges in edge set A.