Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does it make sense to use a map?

I am trying to round up cases when it makes sense to use a map (set of key-value entries). So far I have two categories (see below). Assuming more exist, what are they?

Please limit each answer to one unique category and put up an example.


Property values (like a bean)

age -> 30
sex -> male
loc -> calgary   

Presence, with O(1) performance

peter -> 1
john  -> 1
paul  -> 1
like image 899
kiwicptn Avatar asked Mar 11 '10 20:03

kiwicptn


People also ask

When would a map be useful?

Maps represent the real world on a much smaller scale. They help you travel from one location to another. They help you organize information. They help you figure out where you are and how to get where you want to go.

What are 5 uses of a map?

Answer: Generally, we use maps as a reference to show political boundaries, landforms, water bodies, and the positions of cities. Maps also help us to know the routes of an area, landmarks, location (latitudes and longitudes) of a building or things, etc. Question 5: What is the purpose of a map?

Why are maps useful to everyone?

Maps also help us to know distances so that we know how far away one thing is from another. We need to be able to estimate distances on maps because all maps show the earth or regions within it as a much smaller size than their real size. To do this we need to be able to read the scale on a map.

How do you properly use a map?

Step 1: At first you need to open the Google Maps app. Step 2: Search for a place or tap it on the map. Step 4: To add destination you have to go to the top right and tap more and then add a stop.


2 Answers

Sparse Data Structures (e.g. a sparse array or a matrix):

0 -> value
1 -> value
100 -> value
105 -> value

Also, I would argue that the "Presence" example you listed is better done with a Set data structure (e.g. HashSet in Java or .NET) since the "mapping" part of the map is really not necessary.

like image 116
Eric Petroelje Avatar answered Nov 08 '22 12:11

Eric Petroelje


Remembering function results (caching, buffering, memoization)

10 -> 2
20 -> 7
30 -> zeroesIn(factorial(30))
like image 25
kiwicptn Avatar answered Nov 08 '22 13:11

kiwicptn