Before starting, I want to say that I understand time complexity, and I understand how a hash table is considered O(1) vs an array having a time comp. of O(N) in terms of what you learn. What I don't understand is why looking up something in a hash table is not O(N).
Surely, just because you know the key
, you still have to look your way through the data structure to find it. An analogy might be to knowing someone's name in order to find their phone number in a phone book: you can't just open the book exactly on their name; you still have to work your way through to find their location.
Tl;dr: I want to know how a hash table can retrieve a value
without having to look for said value
through all the keys
:values
before it.