9618/31 May/June 2023 · Question 3 · 6 marks
A hashing algorithm uses key MOD 3 to find where records are stored in a random-access file. (a) Give the hash values of 1050 and 1025. (b) Describe what happens, when a record is stored or found, if the hash value is the same as one calculated before.
Points that gain marks
- 1050 MOD 3 = 0 and 1025 MOD 3 = 2.
- This is a collision: the storage place is already used by a record with a different key.
- To store: search the file linearly from that place to the next free space (closed hashing), or search the overflow area linearly for the next free space (open hashing).
- To find: search the same way, linearly from that place or through the overflow area, until the matching record key is found.
- If it is not found, the record is not in the file.
In this lab: Levels 2 to 4 store records both ways; levels 5 and 6 find them, and stop at an empty place when a record is missing.