O'Reilly logo

A Common-Sense Guide to Data Structures and Algorithms by Jay Wengrow

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sets: How a Single Rule Can Affect Efficiency

Let’s explore another data structure: the set. A set is a data structure that does not allow duplicate values to be contained within it.

There are actually different types of sets, but for this discussion, we’ll talk about an array-based set. This set is just like an array—it is a simple list of values. The only difference between this set and a classic array is that the set never allows duplicate values to be inserted into it.

For example, if you had the set ["a", "b", "c"] and tried to add another "b", the computer just wouldn’t allow it, since a "b" already exists within the set.

Sets are useful when you need to ensure that you don’t have duplicate data.

For instance, if you’re creating an online ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required