hashing john phil dave mary figure an ideal hash table this is the basic idea of hashing the only remaining problems deal with choosing functiondeciding what to do when two keys hash to the same value (this is known as collision)and deciding on the table size hash function if the input keys are integersthen simply returning key mod tablesize is generally reasonable strategyunless key happens to have some undesirable properties in this casethe choice of hash function needs to be carefully considered for instanceif the table size is and the keys all end in zerothen the standard hash function is bad choice for reasons we shall see laterand to avoid situations like the one aboveit is often good idea to ensure that the table size is prime when the input keys are random integersthen this function is not only very simple to compute but also distributes the keys evenly usuallythe keys are stringsin this casethe hash function needs to be chosen carefully one option is to add up the ascii values of the characters in the string the routine in figure implements this strategy the hash function depicted in figure is simple to implement and computes an answer quickly howeverif the table size is largethe function does not distribute the keys well for instancesuppose that tablesize , ( , is prime numbersuppose all the keys are eight or fewer characters long since an ascii character has an integer value that is always at most the hash function typically can only assume values between and , which is this is clearly not an equitable distributionanother hash function is shown in figure this hash function assumes that key has at least three characters the value represents the number of letters in the english alphabetplus the blankand is this function examines only the first three charactersbut if these are random and the table size is , as beforethen we would expect