I was studying about hash tables on hackerearth , where I encounter this code for Implementing the Hash Table with Linear Probing. I have two doubts in this code:-
1) Why they declare hashTable of size 21 (and not of size 20) to hold maximum of 20 elements ?
2) In Insert function , Isn't while loop run infinitly , if after successive iterations value of index become same of the initial value of Index ?
link to hackerearth page:-https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/tutorial/
Code:-
//declaring a hashTable to hold not more than 20 elements
string hashTable[21];
int hashTableSize = 21;
//Insert function
void insert(string s)
{
//Compute the index using the hash function
int index = hashFunc(s);
/*Search for an unused slot and if the index will exceed the hashTableSize then roll back*/
// I have problem in this loop definition
while(hashTable[index] != "")
index = (index + 1) % hashTableSize;
hashTable[index] = s;
}