Hash Table Search

Hash Table Search

  • location of each item is determined by a hash function of the item itself.

Collision Strategies

Linear Probing:

Adding:

  1. Calculate index
Insert item at that index
  1. If it is occupied, check subsequent slots sequentially
  2. If the end of the table is reached, wrap back to the first index (similar to circular array)
  3. Continue until empty slot is found

Searching:

  1. Similar to adding
  2. Continue search until empty slot or when it reaches the start location again, indicating item is not in the table

Chaining:

Adding:

  1. Calculate Index
  2. Add the data at the index using linked list

Searching:

  1. Apply hash function
  2. Use search algorithm for linked list