- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Set Operations

Venn diagram, invented in 1880 by John Venn, is a schematic diagram that shows all possible logical relations between different mathematical sets.

**Examples**

## Set Operations

Set Operations include Set Union, Set Intersection, Set Difference, Complement of Set, and Cartesian Product.

### Set Union

The union of sets A and B (denoted by A ∪ B) is the set of elements that are in A, in B, or in both A and B. Hence, A ∪ B = { x | x ∈ A OR x ∈ B }.

**Example** − If A = { 10, 11, 12, 13 } and B = { 13, 14, 15 }, then A ∪ B = { 10, 11, 12, 13, 14, 15 }. (The common element occurs only once)

### Set Intersection

The intersection of sets A and B (denoted by A ∩ B) is the set of elements which are in both A and B. Hence, A ∩ B = { x | x ∈ A AND x ∈ B }.

**Example** − If A = { 11, 12, 13 } and B = { 13, 14, 15 }, then A ∩ B = { 13 }.

### Set Difference/ Relative Complement

The set difference of sets A and B (denoted by A – B) is the set of elements that are only in A but not in B. Hence, A - B = { x | x ∈ A AND x ∉ B }.

**Example** − If A = { 10, 11, 12, 13 } and B = { 13, 14, 15 }, then (A - B) = { 10, 11, 12 } and (B - A) = { 14, 15 }. Here, we can see (A - B) ≠ (B - A)

### Complement of a Set

The complement of a set A (denoted by A’) is the set of elements which are not in set A. Hence, A' = { x | x ∉ A }.

More specifically, A'= (U - A) where ** U** is a universal set that contains all objects.

**Example** − If A = { x | x belongs to set of odd integers } then A' = { y | y does not belong to set of odd integers }

### Cartesian Product / Cross Product

The Cartesian product of n number of sets A_{1}, A_{2}, ... A_{n} denoted as A_{1} × A_{2} ... × A_{n} can be defined as all possible ordered pairs (x_{1}, x_{2}, ... x_{n}) where x_{1} ∈ A_{1}, x_{2} ∈ A_{2}, ... x_{n} ∈ A__{n}

**Example** − If we take two sets A = { a, b } and B = { 1, 2 },

The Cartesian product of A and B is written as − A × B = { (a, 1), (a, 2), (b, 1), (b, 2)}

The Cartesian product of B and A is written as − B × A = { (1, a), (1, b), (2, a), (2, b)}

- Related Questions & Answers
- Explain Set relations and operations in TOC?
- How instruction set architectures check the result of operations?
- Minimum operations required to set all elements of binary matrix in C++
- Operating System Operations
- Python Boolean Operations
- How query operations can be improved by cascading the operations?
- Minimum operations to make the MEX of the given set equal to x in C++
- Database Operations in C#
- Database operations in Java
- Different Operations on Processes
- String Operations in Python
- Meldable Priority Queue Operations
- Diac Operations and Applications
- What is Microsequencer Operations?
- Java 8 Stream Terminal Operations