Counting the Number of Probes Consider again the code that locates an item or a
ID: 3731680 • Letter: C
Question
Counting the Number of Probes Consider again the code that locates an item or a free slot in the hash table using linear probing private int locate(int index, T key) t 6.5 boolean found = false; while ( !found && (hashTable[index] != null) ) { if (hashTable index].isInO && key.equals (hashTable[index].getKeyO)) found true; // key found else // follow probe sequence index = (index + 1) % hashTable.length; //linear probing // end while // Assertion: either key is found or a null location is reached int result-1; if (found) result index ; return result; 3 // end locate Suppose that index is 2 and key is 57. Trace the code and circle the index of any location that is 15 25 13 5719 16 11 How many locations were circled? (How many probes were made?) How many times did the body of the loop execute? Now suppose index is 2 and key is 99. Trace the code again and circle the index of any location that is accessed 15 25 13 5719 16 11 How many locations were circled? (How many probes were made?) How many times did the body of the loop execute? It should be the case that only one of the traces had the same number of loop executions as probes Show how to modify the locate 0 method given previously so that it will add the number of probes made to a static variable named total Probes.Explanation / Answer
Solution:
Index 2, 3, and 4 was accessed until the key 57 was found.
3 location were circled and two probes were made.
3 times
for 2 and 99.
In this case, the index 2, 3, 4, 5, and 6 will be accessed and at 6 there is NULL so the loop will be terminated
4 locations were circled
5 times the body of the loop executed
Please repost the other parts, I did as much as I could. Thanks :)
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)