//variable to store probing location //calculating the hash code //if the positi
ID: 3795861 • Letter: #
Question
//variable to store probing location
//calculating the hash code
//if the position is empty, immediately return failure...
//...but if it's a match, return the data straight away...
//...otherwise, probe to the next item, looping to zero if necessary
//keep probing until data is found or entire table has been visited
//if the probed element is completely empty, return failure
//if the probed element is a match, return the data...
//...otherwise, keep probing for the next item, looping back to zero if necessary
//if nothing has been returned by now, data is not present
Explanation / Answer
int probe;
//assignment is a constant time operation so O(1)
//here we are checking if table[code] == null which is also a constant time operation so O(1)
//if the position is empty, immediately return failure...
//same here O(1)
//...but if it's a match, return the data straight away...
//...otherwise, probe to the next item, looping to zero if necessary
//The time complexity is O(n) for while loop since we are looping the elements and O(1) for if loop, but as we consider only the biggest term , time complexity is O(n)
//O(n) is also time complexity for whole program for the same reason that we consider only highest term
//keep probing until data is found or entire table has been visited
//same here O(1)
//if the probed element is completely empty, return failure
//same here O(1)
//if the probed element is a match, return the data...
//same here O(1), reason mentioned above
//...otherwise, keep probing for the next item, looping back to zero if necessary
return null;
//if nothing has been returned by now, data is not present
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.