Myths and mistakes
After this: Spot the common wrong ideas and say why each one is wrong.
You now know enough to spot some common wrong ideas. Here are seven things people say about hash maps that are not quite true. Each one comes with the fact and one question. Looking at a wrong idea directly is a good way to remember the right one.
Check 1 of 7
A colleague says a lookup in their hash map took 10,000 comparisons. What is the most likely cause?
Check 2 of 7
You often need to go through your keys in sorted order. What should you use?
Check 3 of 7
Your table has 8 slots and 6 keys, and two of them share a slot. What should you conclude?
Check 4 of 7
You want to cache results for each (user_id, page)(userId, page). What is the right key?
Check 5 of 7
A map holds 100 keys. Which capacity is the most sensible?
Check 6 of 7· in Python
A Python test saves hash('cat') to a file, and a later run compares against it. What happens?
# Run this program twice:print(hash("cat"))# 7190430241105838903 the first time, maybe# -412583900166942571 the second time: a different number// Fixed by Java's specification: the same number on every run, on every machine.System.out.println("cat".hashCode()); // 98262Check 7 of 7
In Java, an object whose hashCode depends on its fields is used as a key, and then one of those fields is changed. What does map.get(key) return?
- Spot the seven common wrong ideas and say why each one is wrong.