Use a membership test to check whether an element belongs to a set, and a subset test to check whether every element of one set belongs to another. Mathematically, test whether or whether .
Membership and Subset Tests
A set is an abstract data type (ADT) that stores distinct, unordered elements. The ADT specifies operations and their behaviour without requiring the programmer to know the underlying implementation.
| Test | Meaning | Example |
|---|---|---|
| Membership | Is element contained in set ? | If , then is true. |
| Non-membership | Is element absent from set ? | For the same set, is true. |
| Subset | Is every element of contained in ? | If , then is true. |
| Proper subset | Is a subset of, but not equal to, ? | is true when and . |
A subset test can be expressed algorithmically as:
FUNCTION isSubset(B, A)
FOR EACH element IN B
IF NOT contains(A, element) THEN
RETURN false
END IF
END FOR
RETURN true
END FUNCTION
For example, checking whether requires testing both and . Since both membership tests are true, the subset test is true.
A common misconception is that a subset must be smaller than the other set. In fact, every set is a subset of itself, so . Only a proper subset must contain fewer elements. The empty set is also a subset of every set.
Exam Technique
For B4.1 Fundamentals of ADTs, distinguish the operation from its implementation. State that membership checks one element, whereas a subset check applies membership to every element of the candidate subset. If asked to construct an algorithm, include an immediate false result when an element is missing and return true only after all elements have been checked.