What does looking up key 5 give you back?
Returning the matching value
Elena Ruiz
How a hash table finds a value
Looking up key 5 gives you ash without changing either pair.
Transcript
Watch the pointer move from the key to the value beside it. You gave the lookup a key because you want that value back.
The pointer is at ash because the second pair has the key you asked for, 5, right beside ash. Now the outline marks the result cell, but it's still blank because the lookup hasn't given you anything back yet. The answer an operation gives back to whoever asked is its return value. So the result cell is for the return value, not for another stored pair.
Now follow the pointer to the first pair and notice whose value it holds: it belongs to key 1. The keys share a bucket, but each has its own pair, so taking the first value would answer for 1 instead of 5.
Now follow the pointer back to the second pair: the lookup reads ash there, so the blank result cell fills with ash. Both pairs stay just as they were and right where they were, because reading a value doesn't take it out of the table. So when you ask for key 5, you get ash because that's the value paired with 5, whether the match comes first or not.