VIRTUAL LABS

Logo

Hashing




Hashing Algorithm using Division Method


Algorithm Steps:


  1. Initialize Hash Table: Create an empty hash table of size p, where p is a prime number.
  2. Hash Function: Define the hash function: hash(k) = k mod p.
  3. Insertion:
    • For each key k to be inserted:
    • Calculate the index using the hash function.
    • If the index is empty, insert the key.
    • If there is a collision, use chaining to resolve it.
  4. Retrieval:
    • To retrieve a key k:
    • Calculate the index using the hash function.
    • Check the list at that index for the key.
  5. Handling Collisions: Use a technique such as chaining or open addressing.