|
|
|
|
|
by tonyarkles
3637 days ago
|
|
As a solid example of this... A fellow student was working on a problem that had a key-value mapping, but instead of storing them in a hash table/map/whatever the language wants to call it, he was storing them as pairs in a list and complaining about the performance on a large data set. I asked him why he wasn't just storing it in a hash table instead. His answer: "Because I sometimes need to iterate over it and get both the key and the value" My brain had to sit and parse what he'd said for a few moments, before I realized what the heck he was talking about. In all of the data structure courses, he'd been taught "A hash table hashes the key, and stores the value in the corresponding slot". In that mental model, there's no way to retrieve the key, only to retrieve the value given the key. I explained to him that real-world implementations do do that, but also store the key along-side the value, so that you can still iterate across it. You could see the look of amazement wash over him, and then he frustratingly declared "Why the hell didn't they mention that?!" |
|