Set





Definition: A collection of unique elements stored together in an unordered, list-like format.



Real Life Example: Instagram account names! Per platform guidelines, no two users can have the exact same Instagram account name due to potential identification issues. A set can be thought of as a real time list of all existing account names: new names can be added, existing names can be discarded, but names that already exist cannot be added again.



Basic Set Operations:

  1. Adding an element. If the element already exists in the set, it will not be added again.
  2. Discarding an element. If the element exists in the set, it will be removed from the set.

Fun Fact: Sets are commonly used for comparing two datasets. Due to the uniqueness of elements in sets, they can be compared to find unions, intersections, differences, and symmetric differences between the two sets of data (see below, assume set A and set B).




Commonly Used In:



Other Similar Data Structures: