22-maps/questions/README.md
For example, here is an inefficient program that uses a loop to find an element among millions of elements.
millions := []int
for _, v := range millions {
if v == userQuery {
// do something
}
}
1: That's right. Maps work in O(1) in average for fast-lookup.
2: Map doesn't work in O(n) time for key lookup.
1: That is when you use a map.
2: Right! Looping over map keys happen in O(n) time. So, maps are the worst data structures for key traversing.
3: Maps don't allow you to add structured data to your program.
5: Slices, maps, and function values are not comparable. So, they cannot be map keys.
map[string]map[int]bool
4: The map contains other maps. The element type of a map can be of any type.
2: That's right. Maps are complex data structures. However, each map value is only a pointer to a map header (which is a more complex data structure).