int hashFn(string key){
int idx=0;
int p=1;
for(int j=0;j<key.length();j++){
idx=idx+(key[j]p)%table_size;
idx=idx%table_size;
p=(p27)%table_size;
}
return idx;
}
How this hashFn is working please explain ??
Hashtable problem
It must be explained well in the video.
here p must be the multiplying factor.
For position 0, p will be 27^0=1, for position 1 p will be 27^1, for position 2, it will be 27^2 and so on…
The hashing formula used here is idx=idx+(key[j] * p)%table_size;
You have a fixed table size, so the hashed index must be in that range, that is less than the table size
So next we perform idx=idx%table_size;
The part in this function, you did not understand well, ask for it specifically,
I want to ask that suppose we are searching for a element named ash containing value 20.
As hashfn will give us that table part which have that value. But in that table there are many nodes having same string value. as we are only passing string key in hashfn so it will give only table no . then how to find that particular string whose value we wanted
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.