2

So, after a collision, a piece of information gets stored in the next bucket. When retrieving the value later with a key, how do we know it has not been shifted due to a collision and that we are in fact receiving the wrong value?

waterlemon
  • 135
  • 4

1 Answers1

4

With linear probing, the appropriate bucket stores both the value and the literal key. So when retrieving, you start in the bucket determined by the hash code and check if the key is the same. If it's not, you move to the next one and check again, and repeat until you find what you're looking for.

Draconis
  • 7,098
  • 1
  • 17
  • 27
  • 1
    This is a bit off-topic, but do linked lists also have both a value and the literal key? Otherwise, what is the point? – waterlemon Oct 07 '18 at 09:46
  • 1
    @boreora For the most part linked lists don't have keys at all. If you're asking about the linked-list approach to dealing with collisions in a hash table, then yes. – Draconis Oct 07 '18 at 16:32