Course contentsShow
← Computer Science
Lesson 62 of 2,8722. Discrete Mathematics for CSFree lesson

Set Union and Intersection

Define union and intersection operations; practice combining sets using these fundamental operations.

Set Union and Intersection

You'll learn how to combine two sets using the union and intersection operations—the two most fundamental ways to create new sets from existing ones.

What Are Union and Intersection?

When working with sets, you'll often need to combine them in specific ways:

Union (∪) brings sets together. The union of sets A and B, written A ∪ B, contains every element that appears in A, in B, or in both. Think of it like merging two friend groups—everyone from either group is invited to the party.

Intersection (∩) finds common ground. The intersection of sets A and B, written A ∩ B, contains only elements that appear in both A and B. It's like finding friends who are in both your study group and your sports team.

Examples

Let's say:

  • A = {1, 2, 3, 4}
  • B = {3, 4, 5, 6}

A ∪ B = {1, 2, 3, 4, 5, 6}
(Everything from either set, no duplicates)

A ∩ B = {3, 4}
(Only elements in both sets)

Special Cases

  • If sets have nothing in common, their intersection is the empty set: {2, 4} ∩ {1, 3} = ∅
  • If one set is a subset of another, their intersection is the smaller set: {1, 2} ∩ {1, 2, 3} = {1, 2}
  • Any set union with itself equals itself: A ∪ A = A

Connection to Logic

Notice the similarity to logical operations you've learned:

  • Union (∪) behaves like logical OR
  • Intersection (∩) behaves like logical AND

Key Takeaway: Union combines all elements from both sets (like OR), while intersection keeps only shared elements (like AND)—these operations let you build new sets from existing ones systematically.