Chapter 13 · SimulationSet ADT Simulator ? ← Chapter 13 Value Add to A Add to B Remove from A Remove from B Clear Both In A? In B? Iterate A A ⊆ B? A = B? Load Example A ∪ B A ∩ B A − B B − A A △ B Random Sets Cancel Set A Set B Example sets loaded. — |A|0 |B|0 |A ∪ B|0 |A ∩ B|0 Close 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.