12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

26 Chap. 2 Mathematical Preliminaries{1, 4} A set composed of the members 1 <strong>and</strong> 4{x | x is a positive integer} A set definition using a set formerExample: the set of all positive integersx ∈ Px is a member of set Px /∈ Px is not a member of set P∅The null or empty set|P|Cardinality: size of set Por number of members for set PP ⊆ Q, Q ⊇ P Set P is included in set Q,set P is a subset of set Q,set Q is a superset of set PP ∪ QSet Union:all elements appearing in P OR QP ∩ QSet Intersection:all elements appearing in P AND QP − QSet difference:all elements of set P NOT in set QFigure 2.1 Set notation.|P| = 3 (because P has three members) <strong>and</strong> |Q| = 2 (because Q has two members).The union of P <strong>and</strong> Q, written P ∪ Q, is the set of elements in either P or Q, whichis {2, 3, 5, 10}. The intersection of P <strong>and</strong> Q, written P ∩ Q, is the set of elementsthat appear in both P <strong>and</strong> Q, which is {5}. The set difference of P <strong>and</strong> Q, writtenP − Q, is the set of elements that occur in P but not in Q, which is {2, 3}. Notethat P ∪ Q = Q ∪ P <strong>and</strong> that P ∩ Q = Q ∩ P, but in general P − Q ≠ Q − P.In this example, Q − P = {10}. Note that the set {4, 3, 5} is indistinguishablefrom set P, because sets have no concept of order. Likewise, set {4, 3, 4, 5} is alsoindistinguishable from P, because sets have no concept of duplicate elements.The powerset of a set S is the set of all possible subsets for S. Consider the setS = {a, b, c}. The powerset of S is{∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}.Sometimes we wish <strong>to</strong> define a collection of elements with no order (like aset), but with duplicate-valued elements. Such a collection is called a bag. 1 Todistinguish bags from sets, I use square brackets [] around a bag’s elements. For1 The object referred <strong>to</strong> here as a bag is sometimes called a multilist. But, I reserve the termmultilist for a list that may contain sublists (see Section 12.1).

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

Saved successfully!

Ooh no, something went wrong!