Tutorial Sheet-4 (Functions)
Tutorial Sheet-4 (Functions)
1. Define a hashing function that uses 63 storage locations as a four-stage process with surnames
as input. The first step is to replace the letters of the surname with integers according to the
following rule: A → 1, B → 2, C → 3 ..., Y→25, Z →26. The second step is to multiply the
letter value by 2i where i is the letter's position in the word, with the leftmost character being
in position 1. The third step is to add the values that represent the letters of the surname. The
final step is to divide this sum by 63. The hashing value is the remainder of this division. For
example, Robb has a value of 144 and a hashing value of 18. You should imagine that the
information needed for Robb is in storage location 18. Carry out this hashing procedure for
Smith, Jones, Brown, Zento, and Ruster.
5. A parking lot has 31 visitor spaces, numbered from 0 to 30. Visitors are assigned parking
spaces using the hashing function h(k) = k mod 31, where k is the number formed from the
first three digits on visitor's license plate.
a) Which spaces are assigned by the hashing function to cars that have these first three digits
on their license plates? 317, 918,007, 110, 111, 310.
b) What can you advise the visitors when the space they are assigned is occupied?