Sets
Computer Science · Data structures
Question 1 of 10
0In set notation, which symbol denotes intersection?
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Sets explained
A set is a collection of items in which each item appears at most once and the order does not matter. Sets are useful for removing duplicates and for comparing groups, such as the students who play two different sports.
The standard notation uses capital letters for sets. The union contains every item that is in A, in B, or in both. The intersection contains only the items that are in both sets. The difference contains the items in A that are not in B.
For two finite sets, the size of the union is found with a formula: . The intersection is subtracted because it was counted in both and .
A common mistake is forgetting that subtraction step. Adding the two sizes without subtracting the overlap counts the shared items twice, and the answer comes out too large.
Most programming languages have a set type too. Python can store a set such as {1, 2, 2, 3}, which keeps only 1, 2 and 3, and it uses & for the intersection.
Worked example
In a class of 30 students, 18 play football, 12 play hockey, and 5 play both. How many students play at least one sport, and how many play neither?
- Let F be the set of football players and H the set of hockey players. Then , and .
- Students who play at least one sport: .
- Students who play neither: .
Check: the 5 students who play both are counted once in the union, not twice.
What you will practise
103 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- A set stores:
- Membership testing in a set is:
- The union of two sets contains:
- The intersection contains:
- The difference A − B contains:
- Adding an element that is already in a set does what?
- Which of these is a set written in standard mathematical notation?
- The symmetric difference of sets A and B contains:
…and 95 more.