How To Find The Union Of Two Sets

9 min read

Understanding how to find the union of two sets is a fundamental skill in mathematics, computer science, and data analysis. Whether you are solving a probability problem, querying a database, or writing code in Python, mastering this concept provides a powerful tool for organizing and manipulating data. The union operation allows you to combine distinct elements from multiple collections into a single, comprehensive set without duplication. This guide explores the definition, notation, step-by-step methods, visual representations, and practical applications of set unions to ensure you can apply this concept confidently in any context Simple, but easy to overlook..

What Is the Union of Two Sets?

In set theory, the union of two sets A and B is the set of elements that are in A, in B, or in both A and B. On top of that, it effectively merges the two collections while strictly adhering to the defining property of a set: every element is unique. If an item appears in both sets, it appears only once in the resulting union It's one of those things that adds up..

The standard mathematical notation for the union of sets A and B is A ∪ B. It is read as "A union B."

Formally, the definition is written as: A ∪ B = { x | x ∈ A or x ∈ B }

This reads: "The union of A and B is the set of all x such that x is an element of A or x is an element of B (or both)." The logical "or" here is inclusive, meaning satisfaction of either condition (or both) qualifies the element for inclusion It's one of those things that adds up..

Step-by-Step Methods to Find the Union

Finding the union can be approached in several ways depending on how the sets are presented—whether as roster lists, set-builder notation, Venn diagrams, or programming data structures Not complicated — just consistent..

1. The Roster Method (Listing Elements)

This is the most intuitive method for finite sets defined by explicit lists.

Steps:

  1. Write down all elements of Set A.
  2. Write down all elements of Set B.
  3. Combine the lists into a single collection.
  4. Remove any duplicate values.
  5. Enclose the final unique elements in curly braces { }.

Example: Let A = {1, 2, 3, 4, 5} and B = {4, 5, 6, 7, 8}.

  1. List A: 1, 2, 3, 4, 5
  2. List B: 4, 5, 6, 7, 8
  3. Combined: 1, 2, 3, 4, 5, 4, 5, 6, 7, 8
  4. Remove duplicates (4 and 5 appear twice): 1, 2, 3, 4, 5, 6, 7, 8
  5. Result: A ∪ B = {1, 2, 3, 4, 5, 6, 7, 8}

2. The Set-Builder Notation Method

When sets are defined by rules rather than lists (e.Day to day, g. , A = {x | x is an even integer} and B = {x | x is a multiple of 3}), you find the union by combining the defining conditions with a logical OR.

Steps:

  1. Identify the condition for Set A (P(x)).
  2. Identify the condition for Set B (Q(x)).
  3. Write the new condition: P(x) OR Q(x).
  4. Express the new set using set-builder notation.

Example:

  • A = {x | x > 0} (Positive numbers)
  • B = {x | x < -2} (Numbers less than -2)
  • A ∪ B = {x | x > 0 or x < -2}

3. Using Venn Diagrams (Visual Method)

A Venn diagram uses overlapping circles to represent sets. The universal set is usually a rectangle enclosing the circles Took long enough..

Steps:

  1. Draw two overlapping circles. Label one A and the other B.
  2. Place elements in the appropriate regions:
    • Elements only in A go in the non-overlapping part of circle A.
    • Elements only in B go in the non-overlapping part of circle B.
    • Elements in both go in the intersection (the overlapping lens shape).
  3. The Union (A ∪ B) is the entire area covered by both circles. Shade the whole of circle A and the whole of circle B.
  4. List every element inside the shaded region.

This visual approach is excellent for verifying that no element has been missed and for understanding the relationship between Union and Intersection.

4. Finding the Union in Programming

In computer science, sets are standard data structures. Finding the union is a built-in operation in almost every major language.

Python:

set_a = {1, 2, 3, 4, 5}
set_b = {4, 5, 6, 7, 8}

# Method 1: Using the union() method
union_set = set_a.union(set_b)

# Method 2: Using the | operator (bitwise OR)
union_set_operator = set_a | set_b

print(union_set)  # Output: {1, 2, 3, 4, 5, 6, 7, 8}

JavaScript:

const setA = new Set([1, 2, 3, 4, 5]);
const setB = new Set([4, 5, 6, 7, 8]);

// Spread operator to merge, Set constructor removes duplicates
const unionSet = new Set([...setA, ...setB]);

console.log(unionSet); // Set(8) {1, 2, 3, 4, 5, 6, 7, 8}

SQL (Database Union): In relational databases, the UNION operator combines result sets of two SELECT statements. Crucially, UNION removes duplicate rows by default (use UNION ALL to keep duplicates) Most people skip this — try not to..

SELECT column_name FROM table_A
UNION
SELECT column_name FROM table_B;

Critical Properties of the Union Operation

Understanding the algebraic properties of unions helps simplify complex expressions and proves useful in discrete mathematics proofs.

  1. Commutative Law: A ∪ B = B ∪ A The order of the sets does not matter.
  2. Associative Law: (A ∪ B) ∪ C = A ∪ (B ∪ C) When combining three or more sets, grouping does not matter. You can write A ∪ B ∪ C without parentheses.
  3. Idempotent Law: A ∪ A = A The union of a set with itself is the set itself (no new elements are added).
  4. Identity Law: A ∪ ∅ = A The union of any set with the empty set (null set) is the original set.
  5. Domination Law: A ∪ U = U The union of any set with the Universal Set U is the Universal Set.
  6. Distributive Laws:
    • A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) (Union distributes over Intersection)
    • **A ∩ (B ∪ C) = (A ∩ B)
  • A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) (Intersection distributes over Union)

Notice the symmetry: union and intersection distribute over each other, which is unusual in algebra and is one reason set theory behaves so cleanly. Two companion results worth memorizing are De Morgan's Laws, which describe what happens when you negate a union:

  • (A ∪ B)′ = A′ ∩ B′
  • (A ∩ B)′ = A′ ∪ B′

In plain English: "not (A or B)" is the same as "not A and not B."

Counting the Union: The Inclusion–Exclusion Principle

When sets overlap, you cannot simply add their sizes, because shared elements get counted twice. The correction is:

|A ∪ B| = |A| + |B| − |A ∩ B|

For three sets, the pattern extends:

|A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|

Example: A survey of 200 people finds 120 like tea (A), 90 like coffee (B), and 40 like both That's the whole idea..

|A ∪ B| = 120 + 90 − 40 = 170 people like at least one drink, leaving 200 − 170 = 30 who like neither.

The alternating add/subtract rhythm — add singles, subtract pairs, add triples — generalizes to any number of sets.

Common Pitfalls to Avoid

Mistake Why It's Wrong
Assuming |A ∪ B| = |A| + |B| Ignores the overlap; double-counts the intersection. Which means
Confusing ∪ with ∩ Union is "OR" (more elements); Intersection is "AND" (fewer elements).
Treating SQL UNION like UNION ALL Plain UNION silently deduplicates, which changes row counts.
Forgetting duplicates vanish in sets {1, 1, 2} and {1, 2} are the same set.
Misreading A ∪ B = B This is true only when A ⊆ B, not in general.

Quick Practice

  1. If A = {a, e, i, o, u} and B = {a, b, c}, find A ∪ B. → {a, b, c, e, i, o, u}
  2. If |A| = 25, |B| = 30, and |A ∪ B| = 40, find |A ∩ B|. → 15
  3. Simplify A ∪ A′. → U, the universal set (Domination/Comp

lementary Law) No workaround needed..

  1. In a class of 50 students, 30 study French, 25 study Spanish, and 10 study both. How many study at least one language? → 30 + 25 − 10 = 45, so 5 study neither.

Union in Practice: Where You Actually Use This

The union operation is not just a classroom abstraction. It shows up constantly in everyday computing and data work:

  • Databases (SQL): The UNION operator stacks the results of two queries into a single result set, automatically removing duplicate rows. Use UNION ALL when you want to keep duplicates and care about performance, since deduplication is expensive.
  • Search and Filtering: A query like "show me results matching tag A or tag B" is a union of two result sets. Boolean search engines are built on this idea.
  • Set Data Structures: Languages like Python (set), Java (HashSet), and JavaScript (Set) provide a .union() method or the | operator precisely because merging collections without duplicates is such a common need.
  • Probability: The probability of "event A or event B" occurring is governed by the same inclusion–exclusion logic: P(A ∪ B) = P(A) + P(B) − P(A ∩ B).

A quick Python illustration ties the theory to code:

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

union_set = A | B          # {1, 2, 3, 4, 5, 6}
# equivalently:
union_set = A.union(B)     # {1, 2, 3, 4, 5, 6}

print(len(union_set))      # 6, not 8 — the overlap {3, 4} is counted once

Notice that the shared elements 3 and 4 appear exactly once. That single behavior — collapse duplicates, keep every distinct element — is the entire essence of union.

Conclusion

The union of sets is one of the most fundamental operations in all of mathematics, and yet its core idea is remarkably simple: combine everything, count each distinct element once. From that simple rule flow a surprising amount of structure — the commutative, associative, and distributive laws that make set algebra so predictable, De Morgan's Laws that let you flip between unions and intersections, and the inclusion–exclusion principle that lets you count overlapping collections accurately.

Mastering union pays off well beyond the theory. But whether you are writing a SQL query, reasoning about probabilities, or merging collections in code, the same mental model applies. Keep three things in mind and you will rarely go wrong: union means "OR," duplicates disappear, and when sets overlap you must subtract the intersection to count correctly. With those principles internalized, the rest of set theory becomes a natural extension of ideas you already understand Simple, but easy to overlook..

Fresh Stories

Just Released

Explore the Theme

Keep the Thread Going

Thank you for reading about How To Find The Union Of Two Sets. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home