Subsets and Supersets

Now that we’ve learned what a set is and how to define one, we want to start using sets to say something. To do this, we’ll first introduce what it means to be a member of a set (∈), and also how sets can be related to each other as subsets (⊆) or supersets (⊇).

Watch the video and then answer the questions below.

Seven-minute video

You can also view this video on YouTube


Subsets and Supersets in Java

Using the Set interface from java.util, we have methods for some set relations, but not everything is provied for us.

containsAll() Returns whether this set is a superset of a given set.

size() Returns the cardinality of the set.


Subsets and Supersets in Python

Python has built-in methods for comparing sets.

issubset() Returns whether another set contains this set

issuperset() Returns whether this set contains another set

You can check whether an item is an element of a set using the in operator


Questions

1. Check your understanding

1. Set elements

Which of the following set theory statements are logically equivalent to true and which are logically equivalent to false:

  Expression True False  
1. a ∈ {r, a, c, b, l, z, k}
2. p ∈ {r, a, c, b, l, z, k}
3. a ∉ {r, a, c, b, l, z, k}
4. p ∉ {r, a, c, b, l, z, k}

Check Answers

2. Set elements again

For the set:

Cakes = {cupcake, carrotcake, doughnut}

which of the following are TRUE, FALSE OR UNDEFINED?

  Expression True False Undefined  
1. Carrot cake ∈ Cakes
2. Doughnut ∈ Cakes
3. { cupcake, doughnut } ∈ Cakes
4. Ø ∉ Cakes
5. cupcake ∉ Cakes

Check Answers

3. Subsets

Which of the following are TRUE, FALSE and UNDEFINED?

  Expression True False Undefined  
1. a ⊆ {a, b, c}
2. {a} ⊆ {a, b, c}
3. ∅ ⊆ {a, b, c}
4. {a, b, c} ⊆ ∅
5. ∅ ∈ {a, b, c}

Check Answers

4. Proper Subsets

Which of the following are TRUE and which are FALSE:

  Expression True False  
1. {monkey} ⊆ {monkey, elephant, zebra}
2. monkey ∈ {monkey, elephant, zebra}
3. ∅ ⊂ {elephant, monkey, zebra}
4. { monkey, elephant, zebra } ⊂ {monkey, elephant, zebra}

Check Answers

5. Subsets and Supersets

Work out the truth value of the following statements given set

S = {Berlin, Belfast, Bratislava, Burnley}:
  Expression True False  
1. {Berlin} ⊂ S
2. {Berlin} ⊆ S
3. S ⊇ {Berlin, Bratislava, Burnely}
4. Ø ⊇ S
5. S ⊇ Ø
6. {Berlin, Belfast, Burnley} ⊅ S

Check Answers

2. On pencil and paper

Given the set S:

S = {a, b, c, d}
  1. List all the subsets for S
  2. List all the proper subsets S

Summary

In this section we have learned about subsets and supersets. In the next section we learn about how to work with sets using set operations.