Hash maps (Python dict, Java HashMap, JS Map) promise O(1) average lookups. Explain how they actually work.
Your answer should cover:
- The journey from a key to a storage location (hash function, buckets).
- What a collision is, why collisions are unavoidable, and one strategy for handling them.
- What the load factor is and why hash maps resize themselves.
- Why lookups are O(1) "on average" but O(n) in the worst case.
- Why keys usually must be immutable / why mutating a key after insertion breaks things.