-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy path11.05.txt
20 lines (16 loc) · 1023 Bytes
/
11.05.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Exercise 11.5: Explain the difference between a map and a set. When might you
use one or the other?
By Faisal Saadatmand
Both are associative containers. They are two implementations of binary search
tree data structure.
In a map the elements are made up of a key-value pairs. The value is mapped to
the key. The key serves as an index into the map and as such is used to access
the data in the structure. We use a map when we need to pair a value (or
multiple values) with a key, such as in the case of a dictionary lookup.
The element of a set contains only a key. In other words, the key is the value.
When we need to access data in a set, we use the key to traverse the set
(tree). We use a set when we need to sort a set of data according to a given
criteria, especially when the storing and sorting is done simultaneously as the
data is begin received. The characteristic of a set (as with the map) allows
quick, and efficient, access to the data, which makes it ideal for word
counting or spell check programs.