Skip to main content

Section 1.3 Set Operations

Subsection 1.3.1 Terminology

Just as there are arithmetic operations on numbers, there are set operations on sets.

Definition 1.3.1. Union.

The set \(C\) is the union of the sets \(A\) and \(B\text{,}\) denoted \(A \cup B,\) if and only if \(C=\{ x | x \in A \mbox{ or } x \in B \}.\)

Example 1.3.2. Union.

Consider \(A=\{a,l,k,s\}\) and \(B=\{a,c,l,k\}\text{.}\) \(A \cup B = \{a,c,l,k,s \}\) because \(a \in A,\text{,}\) \(c \in B,\text{,}\) \(l \in A,\text{,}\) \(k \in A,\text{,}\) and \(s \in B\text{.}\) Note it does not matter if we say because \(a \in A\) or because \(a \in B\text{.}\) This is further discussed in Section 2.1

Checkpoint 1.3.3. Compare/Contrast.

Union can be thought of as taking the elements of the first set and adding any elements of the second set that are different. Our question is how does union differ from addition?

Hint

Try unions of \(A=\{1,2,3\}\) with the following sets \(B_1=\{4,5,7\}\text{,}\) \(B_2=\{3,4,5\}\text{,}\) and \(B_3=\{2,3\}\text{.}\)

Definition 1.3.4. Intersection.

The set \(C\) is the intersection of the sets \(A\) and \(B\text{,}\) denoted \(A \cap B,\) if and only if \(C=\{ x | x \in A \mbox{ and } x \in B \}.\)

Watch the video in Figure 1.3.5 demonstrating reading the set intersection definition twice. The first time think about what set intersection is. The second time think about how it illustrates reading and understanding a definition.

Figure 1.3.5. Understanding the set intersection definition
Definition 1.3.6. Difference.

The set \(C\) is the difference between the sets \(A\) and \(B\text{,}\) denoted \(A-B,\) if and only if \(C=\{ x | x \in A \mbox{ but } x \not\in B \}.\)

Checkpoint 1.3.7. Compare/Contrast.

Just as we considered how union is like addition we can compare and contrast set difference with subtraction.

Hint

Try the set difference of \(A=\{1,2,3\}\) with the following sets \(B_3=\{2,3\}\text{,}\) \(B_2=\{3,4,5\}\text{,}\) and \(B_1=\{4,5,7\}\text{.}\)

Checkpoint 1.3.8. Algorithmic complexity.

A programmer must consider how to implement an operation like set difference.

(a)

Find \(A-B\) for \(A=\{1,3,5,7,9\}\) and \(B=\{1,3,9\}\text{.}\)

(b)

Set difference must remove from \(A\) every element in \(B\text{.}\) Consider the following psuedo-code.

for x in A do
  for y in B do
     if y==x then
       remove(A,x)
       exit inner for loop
      end if
  end for
end for

How many times will the comparison (if x==y line) be run for these sets \(A\) and \(B\text{.}\)

(c)

If the psuedo-code algorithm were reversed so the outside loop were for \(B\) and the inside loop for \(A\) would it change the number of comparisons?

(d)

Can you think of any optimizations of this algorithm?

In many circumstance there is a universal set that is part of the context for a problem. It may or may not be explicitly stated. For example the set of all integers may be the universal set for discussion of even and odd numbers.

Definition 1.3.9. Complement.

The set \(C\) is the complement of the set \(A\) with respect to the universal set \(U\text{,}\) denoted \(\neg A\) or \(\overline{A}\text{,}\) if and only if \(C=U-A.\)

Definition 1.3.10. Power Set.

The set \(P\) is the power set of a set \(A,\) denoted \(\Pow(A)\) or \(2^A,\) if and only if \(P\) is the set of all subsets of \(A.\)

For example if \(A=\{0,1\}\) then \(\Pow(A)=\{ \emptyset, \{0\}, \{1\}, \{0,1\}\}.\)

Checkpoint 1.3.11. Developing Power Sets.

Power sets are sets. This means they are unordered. However, to generate them it helps us list all subsets if we impose some convenient order. The following suggest parts of a heuristic for listing elements of power sets. We consider the power set of \(S=\{a,b,c\}\text{.}\)

(a)

There are subsets of \(S\) of size 0,1,2, and 3. What is the only subset of size 0? What is the only subset of size 3?

(b)

List all subsets of size 1.

(c)

List all subsets of size 2.

(d)

There are an equal number of subsets of size 1 and size 2 for \(S\text{.}\) Find a logical correspondence between the subsets of size 1 and size 2 (pair each subset of size 1 with a subset of size 2).

(e)

In general for a set of size \(n\) how could one generate all subsets? Note the steps above only suggest two parts of an algorithm.

Definition 1.3.12. Cartesian Product.

The set \(C\) is the Cartesian product of the sets \(A\) and \(B,\) denoted \(A \times B,\) if and only if \(C=\{(a,b) | a \in A \mbox{ and } b \in B. \}.\)

For example if \(A=\{0,1\}\) and \(B=\{a,b\}\) then \(A \times B =\) \(\{(0,a), (0,b), (1,a),\) \((1,b)\}.\)

Note for a set \(A\) and positive integer \(n \ge 1\) we use the notation \(A^n\) to mean \(n\) copies of \(A\) in a Cartesian product. For example, \(A^3 = A \times A \times A\text{.}\)

Definition 1.3.13. Size of.

We define the size of a finite set \(A\text{,}\) denote \(|A|\) to be the number of elements it contains.

For example if \(A=\{a,b,c\}\) then \(|A|=3.\) There are ways to define the size of infinite sets, but those must wait for later classes.

Checkpoint 1.3.14.

Subsection 1.3.2 Practice

Figure 1.3.15. Typical Venn Diagram
Checkpoint 1.3.16.

Identify the following in the diagram above.

  1. \(\displaystyle A \cup B\)
  2. \(\displaystyle A \cap B\)
  3. \(\displaystyle A-B\)
  4. \(\displaystyle B-A\)
  5. \(\displaystyle \neg A\)
  6. \(\displaystyle \neg B\)
Checkpoint 1.3.17.

Calculate the following for \(A=\{0,1,2\}\) and \(B=\{0,1\}.\)

  1. \(\displaystyle \Pow(A)\)
  2. \(\displaystyle A \times B\)
  3. \(\displaystyle B \times A\)
  4. \(\displaystyle A-B\)
  5. \(\displaystyle B-A\)
Checkpoint 1.3.18.

Perform the set operations indicated on the sets below. The universal set is all integers.

  • \(A=\{n | n=2k \) for some integer \(k\}\)
  • \(B=\{n | n=5k \) for some integer \(k\}\)
  • \(C=\{n | n=6k \) for some integer \(k\}\)
  • \(D=\{n | n=10k \) for some integer \(k \}\)
  1. \(\displaystyle A \cup B\)
  2. \(\displaystyle A \cap B\)
  3. \(\displaystyle C \cap D\)
  4. \(\displaystyle A-B\)
  5. \(\displaystyle B-A\)
  6. \(\displaystyle \neg A\)
  7. \(\displaystyle \neg B\)