Here is my understanding of linear probing.
For insertion: - We hash to a certain position. If that position already has a value, we linearly increment to the next position, until we encounter an empty position, then we insert there. That makes sense.
My question revolves around lookup. From descriptions I have read, I believe lookup works like this:
- We look at the position the item we are looking for hashes to.
- If the position is empty, we return Not Found
- If the position is full, we move linearly to positions until we either encounter the value we are looking for, or we encounter an empty position (meaning not found)
So how does this work when we delete an item from a hash? Wouldn't that mess up this lookup? Say two items hash to the same position. We add both items, then delete the first one we added. So now, the expected position of the second item (which had to be moved to a different position, since the first item originally occupied it) is empty. Does deleting handle this in some way?