What is special about a set?
Options
- Stores each value once; fast membership checks (Correct option)
- It always keeps its values in sorted order
- It can only store numbers, never text values
- It allows duplicates and keeps their order
Answer
It stores each value only once and checks 'is this in the set?' very quickly
Why
A set is a collection with no duplicates. Adding the same value twice leaves one copy.
Python: s = {1, 2, 2, 3} becomes {1, 2, 3}. Java: HashSet.
It is the usual tool for removing duplicates and for fast membership checks (x in s is O(1) on average, while in a list it is O(n)).
Remember
Set = unique values + fast membership check.