Course Programming Logic

Set

Course's Page 2 min Text by
User Image
Thiago Nepomuceno

In previous lessons, we learned some more advanced data structures. In particular, we learned the map (or dict) and set. In this section, we will use these two structures to solve some practical exercises.

When you go to solve the exercises it is important to think about how these two structures can improve your solution, either by making it simpler or more efficient.

Complexity

The complexity of the operations of map and set change from one language to another. While in C++ these structures are implemented using a Red-Black Tree in Python they are implemented using Hash Table.

For this reason, the operations of adding elements and checking whether an element belongs to the structure cost in C++. While in Python, these operations cost in the average case.

However, due to the nature of Hash Table there can be collisions in mapping, resulting in operations.

Practice

As always, let's put these tips into practice. The exercises in this section should be solved in around 20 to 30 minutes.

If you are preparing for Coding Interviews keep practicing your English explanations.