Hashing
Hashing Algorithm using Division Method
Algorithm Steps:
- Initialize Hash Table: Create an empty hash table of size p, where p is a prime number.
- Hash Function: Define the hash function: hash(k) = k mod p.
- 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.
- Retrieval:
- To retrieve a key k:
- Calculate the index using the hash function.
- Check the list at that index for the key.
- Handling Collisions: Use a technique such as chaining or open addressing.