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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Set Data Structures<br />

Next: Kd-Trees Up: Data Structures Previous: Graph Data Structures<br />

Set Data Structures<br />

Input description: A universe of items and a collection of subsets ,<br />

where .<br />

Problem description: Represent each subset so as to efficiently (1) test whether , (2) find the<br />

union or intersection of and , and (3) insert or delete members of S.<br />

Discussion: In mathematical terms, a set is an unordered collection of objects drawn from a fixed<br />

universal set. However, it is usually useful for implementation to represent each set in a single canonical<br />

order, typically sorted, so as to speed up or simplify various operations. Sorted order turns the problem<br />

of finding the union or intersection of two subsets into a linear-time operation - just sweep from left to<br />

right and see what you are missing. It also makes possible element searching in sublinear time. Finally,<br />

printing the elements of a set in a canonical order paradoxically reminds us that order really doesn't<br />

matter.<br />

We distinguish sets from two other kinds of objects: strings and dictionaries. If there is no fixed-size<br />

universal set, a collection of objects is best thought of as a dictionary, as discussed in Section . If the<br />

order does matter in a subset, i.e. if is not the same as , then your structure is more<br />

file:///E|/BOOK/BOOK3/NODE133.HTM (1 of 4) [19/1/2003 1:30:10]

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

Saved successfully!

Ooh no, something went wrong!