Set ADT Simulator

A Set stores unique elements. Membership is more important than position: duplicates are rejected, order is not part of the mathematical abstraction, and core operations include union, intersection, difference, and subset tests.

AddAverage O(1)
HasAverage O(1)
DeleteAverage O(1)
DuplicatesNot allowed

Set operations

350 ms

Set A

Set B

Example sets loaded.

|A|0
|B|0
|A ∪ B|0
|A ∩ B|0

Set concepts

Uniqueness

Adding an element already present in a set does not create a duplicate and does not change the set size.

Membership

Set algorithms usually ask whether an element belongs to a set rather than where that element is stored.

Mathematical operations

Union combines elements, intersection keeps common elements, and difference keeps elements present in one set but not the other.

Implementation note

Java HashSet is backed by hashing and offers average constant-time membership operations; TreeSet keeps elements ordered with logarithmic operations.

Set operation summary

OperationMeaning
A ∪ BElements in A or B or both.
A ∩ BElements common to A and B.
A − BElements in A but not in B.
A △ BElements in exactly one of the two sets.
A ⊆ BEvery element of A is also in B.
A = BA and B contain exactly the same elements.