How do hash tables accomplish O1 association between a key a

How do hash tables accomplish O(1) association between a key and a value?

make index through the hash function by inputting key.
This index is unique in the table. So we just need only one compare get value from the hash.

Solution

Yes, we have to write an hash function which has only a small operation which will take only constant time i.e. O(1). So that we get the index number of the array, which we caqll it as hash table. So we can get the required value from that index(hash) or for inserting also.

Ex: we want to insert 5 in the hash table of size 10. If we use the hash function like kmodn, i.e. 5mod10=>5. So in hash 5 we will store 5.

How do hash tables accomplish O(1) association between a key and a value? make index through the hash function by inputting key. This index is unique in the tab

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site