Logout

7.1.8 Describe the use of hash algorithms to save and retrieve records in a direct access file.

Teaching Notes:
Students should understand the use of modulo operators (mod, div) in the construction of a hash function. See also 5.2.3.

Sample Question 1:

A company making car parts keeps a computerised file of records containing the name,
code and price of each item it has for sale. Direct access will be used to access these
records whenever a sale is made.

(a) Suggest why direct access was chosen for this application. [2 marks]

(b) Explain how a hashing algorithm would be used in conjunction with the creation
of this file. [2 marks]


(c) Explain why the hashing algorithm should be carefully chosen. [2 marks]

The hashing algorithm to be used is shown below.
Address = key % 1000

(d) (i) Identify the record address generated for the key field 4231. [1 mark]

(ii) Suggest what would happen if, subsequently, a new record with the key
field 6231 was added to the file. [3 marks]

Sample Question 2:

(g) Suggest two ways that data would be accessed given the file organization method
you suggested in part (f) (a question in which you would have suggested direct file access as an alternative to sequential - HL 2 May 2008, question 3). [4 marks]

<

JSR Notes: