Maps in a nutshell
Imagine that you are looking for a word in a dictionary. The word itself is unique and can be considered a key. The meaning of this word can be considered the value. Therefore, the word and its meaning form a key-value pair. Similarly, in computing, a key-value pair accommodates a piece of data in which the value can be found by searching with the key. In other words, we know the key and we can use it to find the value.
A map is an Abstract Data Type (ADT) that manages key-value pairs (known as entries) via an array. The characteristics of a map include the following:
- Keys are unique (that is, no duplicate keys are allowed).
- We can view the list of keys, the list of values, or both.
- The most common methods to work with a map are
get()
,put()
, andremove()
.
Now that we've briefly overviewed the notions of linked lists and maps, let's begin our coding challenges.