for(int = <key length() ++int letter key charat( hashval hashval letterreturn hashval arraysize/end hashfunc (/left to right /get char code /multiply and add /mod here we start with the leftmost letter of the word (which is somewhat more natural than starting on the right)and we have only one multiplication and one addition each time through the loop (aside from extracting the character from the stringthe hashfunc (method unfortunately can' handle strings longer than about seven letters longer strings cause the value of hashval to exceed the size of type int (if we used type longthe same problem would still arise for somewhat longer strings can we modify this basic approach so we don' overflow any variablesnotice that the key we eventually end up with is always less than the array size because we apply the modulo operator it' not the final index that' too bigit' the intermediate key values it turns out that with horner' formulation we can apply the modulo operator (%at each step in the calculation this gives the same result as applying the modulo operator once at the end but avoids overflow (it does add an operation inside the loop the hashfunc (method shows how this lookspublic static int hashfunc (string keyint hashval for(int = <key length() ++/left to right int letter key charat( /get char code hashval (hashval letterarraysize/mod return hashval/no mod /end hashfunc (this approach or something like it is normally taken to hash string various bitmanipulation tricks can be played as wellsuch as using base of (or larger power of instead of so that multiplication can be effected using the shift operator (>>)which is faster than the modulo operator (%you can use an approach similar to this to convert any kind of string to number suitable for hashing the strings can be wordsnamesor any other concatenation of characters