Complete the code to calculate the hash index for a given key.
int hashIndex = key [1] tableSize;The modulo operator (%) is used to ensure the hash index stays within the table size.
Complete the code to find the next index in linear probing.
index = (index [1] 1) [2] tableSize;
In linear probing, we move to the next slot by adding 1 and then taking modulo to wrap around.
Fix the error in the insertion loop to handle collisions correctly.
while (table[index] != null && table[index].key != key) { index = (index [1] 1) % tableSize; }
We add 1 to the index to check the next slot during collision handling.
Fill both blanks to complete the search method using linear probing.
int index = key [1] tableSize; while (table[index] != null && table[index].key != key) { index = (index [2] 1) % tableSize; }
The initial index is calculated using modulo (%). Then, we add 1 and modulo again to handle collisions.
Fill both blanks to complete the insertion method with linear probing collision handling.
int index = key [1] tableSize; while (table[index] != null && table[index].key != key) { index = (index [2] 1) % tableSize; } table[index] = new Entry(key, value);
Calculate initial index with modulo (%), then add 1 and modulo again to find the next free slot. Finally, insert the new entry at the found index.
