Greedy Algorithms
We consider the selection of two basketball teams at a neighborhood playground to illustrate the greedy method. Usually the top two players are designated captains. All other players line up while the captains alternate choosing one player at a time. Usually, the players are picked using a greedy strategy. That is, the captains choose the best unclaimed player. The system of selection of choosing the best, most obvious, or most convenient remaining candidate is called the greedy method. Greedy algorithms often lead to easily implemented efficient sequential solutions to problems. Unfortunately, it also seems to be that sequential greedy algorithms frequently lead to solutions that are inherently sequential — the solutions produced by these algorithms cannot be duplicated rapidly in parallel, unless NC equals P. In the following subsections we will examine this phenomenon. We illustrate some of the important aspects of greedy algorithms using one that constructs a maximal independent set in a graph. An independent set is a set of vertices of a graph that are pairwise nonadjacent. A maximum independent set is such a set of largest cardinality. It is well known that finding maximum independent sets is NP-hard. An independent set is maximal if no other vertex can be added while maintaining the independent set property. In contrast to the maximum case, finding maxima? independent sets is very easy. Figure 7.1.1 depicts a simple polynomial time sequential algorithm computing a maximal independent set. The algorithm is a greedy algorithm: it processes the vertices in numerical order, always attempting to add the lowest numbered vertex that has not yet been tried. The sequential algorithm in Figure 7.1.1, having processed vertices 1,... , j -1, can easily decide whether to include vertex j. However, notice that its decision about j potentially depends on its decisions about all earlier vertices — j will be included in the maximal independent set if and only if all j' less than j and adjacent to it were excluded.