Foundational Programming Concepts: Sets

Draft 2 minutes read

In this series we look at some foundational programming concepts. This is not a course about how to program in general. Rather we look into specific tools, what they represent, when should we use them, and also situations where they are not the right choice.

What is a Set

A set is a collection of elements that are unique.

From this definition we can figure out some interesting properties:

A set is usually implemented using a binary tree or a hashmap. Although you don’t necessarily need to know what this means, it is important to know that this gives sets the following properties:

What does it mean for an element to be unique?

In practice two elements are unique if they are not equal, i.e.: a != b.

This will depend on your language, but broadly speaking if your element is primitive (boolean, number or a string) then it just means that they are different.

When do I use a set