Sets — solutions
Solutions to the practice problems at the end of Sets.
Problem 1: Set-builder
Section titled “Problem 1: Set-builder”- . The multiples of three among .
- . The values of for .
- . The pairs with out of the four pairs in .
Problem 2: Operations by hand
Section titled “Problem 2: Operations by hand”- .
- .
- .
- .
- .
- By inclusion–exclusion with , , , , , , and , we get . The union is , which checks out.
Problem 3: Inclusion and exclusion
Section titled “Problem 3: Inclusion and exclusion”Let be the set of students taking math and the set taking computer science. We have , , and . Then
So 48 students take at least one of the two courses, and take neither.
Problem 4: Subsets of a small set
Section titled “Problem 4: Subsets of a small set”The eight subsets of are , , , , , , , and . In general, a set with elements has subsets.
Four of these contain : , , , and . In general, exactly half of the subsets of a nonempty set contain any one chosen element, because fixing that element to be “in” or “out” splits the subsets into two equal classes.
Problem 5: Prove a set identity
Section titled “Problem 5: Prove a set identity”We show that and vice versa.
Forward direction. Let . Then and , so or , and in either case . If , then ; if , then . Either way, .
Reverse direction. Let . Then or . In the first case, and , so and , so . The second case is symmetric.
Both inclusions hold, so the two sets are equal.
Problem 6: Common letters
Section titled “Problem 6: Common letters”def common_letters(s, t): return {c.lower() for c in s if c.isalpha()} & {c.lower() for c in t if c.isalpha()}The two comprehensions build sets of lowercased letters from each string, and & intersects them.
Problem 7: Jaccard by hand
Section titled “Problem 7: Jaccard by hand”The word sets are and . The intersection is (no word appears in both), and the union has seven distinct words, so
The score is zero even though the two sentences are intuitively related: “rose” and “roses” count as different words under this tokenization. Reducing words to a common root (stemming or lemmatization) before computing the sets would raise the score.