18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Generating Subsets<br />

Next: Generating Partitions Up: Combinatorial Problems Previous: Generating Permutations<br />

Generating Subsets<br />

Input description: An integer n.<br />

Problem description: Generate (1) all or (2) a random or (3) the next subset of the integers .<br />

Discussion: A subset describes a selection of objects, where the order among them does not matter.<br />

Many of the algorithmic problems in this catalog seek the best subset of a group of things: vertex cover<br />

seeks the smallest subset of vertices to touch each edge in a graph; knapsack seeks the most profitable<br />

subset of items of bounded total size; and set packing seeks the smallest subset of subsets that together<br />

cover each item exactly once.<br />

<strong>The</strong>re are distinct subsets of an n-element set, including the empty set as well as the set itself. This<br />

grows exponentially, but at a considerably smaller rate than the n! permutations of n items. Indeed, since<br />

1,048,576, a brute-force search through all subsets of 20 elements is easily manageable, although<br />

by n=30, 1,073,741,824, so you will certainly be pushing things.<br />

By definition, the relative order among the elements does not distinguish different subsets. Thus<br />

is the same as . However, it is a very good idea to maintain your subsets in a sorted or canonical<br />

order, in order to speed up such operations as testing whether two subsets are identical or making them<br />

file:///E|/BOOK/BOOK4/NODE152.HTM (1 of 4) [19/1/2003 1:30:44]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!