Chapter 13 · Simulation

Set ADT Simulator

← Chapter 13

Set A

Set B

Example sets loaded.

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

Set ADT Simulator

A set stores unique elements. What matters is membership, not position: duplicates are rejected, order is not part of the mathematical abstraction, and the core operations are union, intersection, difference and subset tests.

How to use it

  • Type a value and add it to, or remove it from, set A or set B; In A? and In B? test membership.
  • The operation buttons (∪, ∩, −, △, ⊆, =) write their result below the sets right away; membership tests and Iterate A animate the elements they examine.
  • Load Example and Random Sets replace both sets; Cancel stops a running animation.

Set concepts

  • Uniqueness: adding an element that is already present creates no duplicate and leaves the size unchanged.
  • Membership: set algorithms ask whether an element belongs to the set, not where it is stored.
  • Implementation note: Java's HashSet uses hashing and tests membership in expected constant time; TreeSet keeps its elements sorted and does its operations in logarithmic time.

Set operations at a glance

OperationMeaning
A ∪ BElements in A, in B, or in 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.