April 2018
Intermediate to advanced
322 pages
6h 57m
English
As we have discussed earlier, a hash key is obtained by finding out the remainder when we divide the phone number with the total slot of table (table size). To generate the hash key, we will implement the HashFunction() function as follows:
int HashTable::HashFunction(int key){ return key % TABLE_SIZE;}
Since we have 10 data items, we define TABLE_SIZE as 7. By using this function, we can get a hash key for an inputted key in the operations of the HashTable. Since the implementation of the HashFunction() function is quite simple, the time complexity of this function will be O(1) for all cases.