What is Hashing and it’s internal implementation.
What is hashing ?
Hashing refers to the process of generating a fixed-size output from an input of variable size using the mathematical formulas known as hash functions. Ex. The amount of data on the internet is growing exponentially every day, making it difficult to store it all effectively. In day-to-day programming, this amount of data might not be that big, but still, it needs to be stored, accessed, and processed easily and efficiently. Component of hashing:
1.Key - 2.Hash Function 3.Hashtable
Hashing is the process of mapping keys, and values into the hash table by using a hash function.
what is internal working of the hashing?
My Approch :
map<int,int> mp;
int pair = make_pair(1,2);
mp.add(pair);
for(int i=0;i<5;i++)
{
}
yogita 1
amruta 3
hashfunc()
{
int key;
string value;
cin>>key;
cin>>value;
string arr[2];
for(int i=1;i<2;i++)
}
asked me not to use stl ?
still used below
unordered_set<string,int> names;
names.add(yogita,1);
Then he explained right approch :
Right Approch:
func hashingfunc(string key){
// xyz key -> index
int index;
index = (key* 77) % 99;
return index;
}
yogita 1
yogesh 3
array a, b;
index = hashingfunc(key);
a[index] = key;
b[index] = value; -> insert, search, delete
asked me to write search and delete approch -
array a, b;
index = hashingfunc(key);
a[index] = key;
b[index] = value; -> insert, search, delete
index = hashfunc(key);
a[index] =key;
b[index] =value;
search(string yogita ,array a, array b)
{
int index=hashfunc(key);
cout<<b[index];
}
delete(key)
{
int index=hashfunc(key);
b[index]=0;
}
What is Collision? The hashing process generates a small number for a big key, so there is a possibility that two keys could produce the same value. The situation where the newly inserted key maps to an already occupied, and it must be handled using some collision handling technology.
Collision is handled by collision handling techniques.