CST-370 Week 6
This week, I learned about linear probing in hash tables. It's a way to handle collisions within a hash table. When a key is placed into a table and its index is already occupied, it checks one by one until there is an empty space left.
A visual example:
Index: 0, 1, 2, 3, 4, 5
Value: _, _, _, _, _, _
Insert key 50
50 % 6 = 2
Index: 0, 1, 2, 3, 4, 5
Value: _, _, 50, _, _, _
Insert key 20
20 % 6 = 2 (collision in index 2)
(2 + 1) % 6 = 3 (index 3 is open)
Index: 0, 1, 2, 3, 4, 5
Value: _, _, 50, 20, _, _
I've watched previous lectures to study what I've answered incorrectly in past quiz assignments.
Comments
Post a Comment