Question: 3) Converting a character string to an integer (Hashing) If your search key is a character string-such as a name-you could convert it into an
3) Converting a character string to an integer (Hashing) If your search key is a character string-such as a name-you could convert it into an integer before applying the hash function h(x). To do so, you could first assign each character in the string an integer value. For example, for the word "NOTE" you could assign the ASCII values 78, 79, 84, and 69, to the letters N, O, T, and E, respectively. Or, if you assign the values 1 through 26 to the letters A through Z, you could assign 14 to N, 15 to O, 20 to T, and 5 to E If you now simply add these numbers, you will get an integer, but it will not be unique to the character string. For example, the string TONE" will give you the same result. Instead, write the numericvalue for each character in binary and concatenate the results. If you assign the values 1 through 26 to the letters A through Z, you obtain the following for the string "NOTE" N is 14, or 01110 in binary O is 15, or 01111 in binary T is 20, or 10100 in binary E is 5, or 00101 in binary Concatenating the binary values gives you the binary integer which is 474,757 in decimal. You can apply the hash function x mod tablesize for x 474,757
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
