# My professor claims that inserting the same key into a hash table again will lead to a collision … – Is he really right?

My whole life I thought

a collision is a situation that occurs when two distinct pieces of data have the same hash value.

Everything looks a little bit different now: A few days ago we had to analyse common collision resolution strategies to handle the event that at least two keys being hashed to the same slot of an ordinary hash table. As mentioned above, to my knowledge (as well as my intuition) when inserting the very same key $$k$$ – that is already assigned to a slot of a hash table $$T$$ – again, nothing (special) happens and $$T$$ remains unchanged.

I wonder now, if i misunderstood this basic concept, since my professor claims, that inserting the key $$k$$ into a hash table $$T$$ again will lead to a collision anyway and we have to analyse some collision resolution strategies in this case too …

• Well, I suppose it's not that interesting to say that you have a collision if you reinsert a key that is already in the table. It gets more interesting if that can happen for two distinct keys as you say. It seems that you know that collisions (obviously) happen for the same keys, but less obviously also when the keys are distinct. – Juho Jan 24 '19 at 20:42
• Whether and how two things are (considered) the same or different is sometimes one of the biggest, hardest and most confusing (philosophical and practical) questions and problems. I am not surprised if you or even your professor are getting confused or looking like trying to confuse others. – John L. Jan 24 '19 at 21:49
• How does your professor use her collision? It is a minor matter to call anything whatever she wants; it is probably more significant how the name/concept is used and whether it is used consistently, at least in her course. – John L. Jan 25 '19 at 2:57

I suppose one could define the word however you like, but I've always understood it to mean the same thing you are talking about. Here I'm assuming if you try to insert a key the second time, no change is made, as it is already present. If inserting the key caused a second copy to be inserted somewhere, then I think it's more ambiguous and in any formal analysis it would be best to define precisely what you mean by a collision and state whether you consider that a collision, to avoid confusion.

What do you mean by "collision", and what does your professor mean?

If you try to insert a key into a hash table, the usual case should be that there is no key with the same hash in the table yet. In that case, no collision, and you insert the key. If there is a key with the same hash already there, I would say that either the same key is already there and I'd say "no collision", or it is a different key that has the same hash by bad luck, and I'd call that "a collision". Your professor might use the term "collision" for both cases.

PS. Quite often when you have a hash table with k slots, we use hash(key) modulo k to pick a slot, so until we change the number of slots, hash(key) modulo k is effectively the hash function that we are using, and we could call it a collision if two keys want to be stored in the same slot.