11.4k views
2 votes
Given the hash function as h(key) = key mod m where m-3, create an hash table for these entities grven in order below: (e.g. 213, John is the fint entity to be entered in your hash table): 213, John 122, Mark 345, Jane 234, Steph 340, Hong 423, Linda 143, Mary 467, Tonia 388, Jim 229, Hey a. Using the hast table mentioned above, how many operations are needed to find whether the given entity 90 . Michacl is in the table or not. b. What is the worst case scencrio for hash tables?

User Ghokun
by
8.0k points

1 Answer

0 votes

Final answer:

To create a hash table using the given hash function, hash each entity and put it in the corresponding slot. Calculate the hash value of the given entity to determine its presence in the table. The worst case scenario for hash tables arises when all entities have the same hash value.

Step-by-step explanation:

To create a hash table using the given hash function h(key) = key mod m, we need to hash each entity and put it in the corresponding slot in the table. The hash table will have a size of m (in this case, m=3). Here's the hash table for the given entities:

SlotEntity0123, John1122, Mark2345, Jane

(a) To find whether the entity 90, Michael is in the table or not, we need to calculate its hash value using the hash function. Since h(90) = 90 mod 3 = 0, we check the slot 0 in the hash table. We find that there is no entity with key 90, so Michael is not in the table. This requires 1 operation.

(b) The worst case scenario for hash tables is when all the entities have the same hash value and are stored in the same slot. This can result in a long chain of entities in that slot, leading to slower search operations.

User Wizardwerdna
by
8.0k points