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

Set Difference and Complement

Define set difference and complement operations; understand how to remove elements from sets.

Set Difference and Complement

What you'll learn: How to remove specific elements from sets using difference and complement operations.

What is Set Difference?

The set difference operation, written as A - B or A \ B, creates a new set containing all elements that are in set A but not in set B. Think of it like subtraction: you're removing B's elements from A.

Example:

  • Let A = {1, 2, 3, 4, 5}
  • Let B = {3, 4, 6, 7}
  • A - B = {1, 2, 5} (we removed 3 and 4 because they're in B)
  • B - A = {6, 7} (different result! order matters)

Notice that A - B is not the same as B - A. This operation is not commutative.

What is Set Complement?

The complement of a set A, written as A' or Aᶜ, contains everything that is not in A, but within some universal set U. You must always specify your universal set first.

Analogy: If the universal set is "all students in your class," and A is "students who passed the exam," then A' is "students who failed the exam."

Example:

  • Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} (universal set)
  • Let A = {2, 4, 6, 8, 10}
  • A' = {1, 3, 5, 7, 9} (everything in U that's not in A)

Notice that complement is really just set difference from the universal set: A' = U - A

Key Relationship

Set difference and complement are closely related. The complement is just the difference between the universal set and your set.

Key Takeaway: Set difference (A - B) removes elements of B from A, while complement (A') gives you everything in the universal set except A.