Six original Cambridge-style questions on file organisation, file access and hashing, with mark points.
Describe the difference between a serial file and a sequential file.
Explain how a record is located in a random file, and why this is faster than searching a serial file.
A random file has addresses 0 to 49. The hashing algorithm is Key MOD 50 and collisions are stored at the next free address. The keys 1207, 3457, 2058 and 907 are inserted in that order into an empty file. State the address of each record.
For each situation, state the most suitable file organisation and justify your choice.
(a) A bank's monthly run that adds interest to every savings account.
(b) A library system that must show the details of one book as soon as its ISBN is scanned.
Describe two methods of handling a collision when writing a record to a random file.
Each record in the random file Stock.dat is of type ItemRecord, with an INTEGER field ItemCode. There are addresses 0 to 499, the hash is ItemCode MOD 500, an empty address has ItemCode 0, and collisions use the next free address. Write a function FindItem(Code : INTEGER) RETURNS INTEGER that returns the address of the record with that code, or -1 if it is not in the file.
Address ← Code MOD 500 and Count ← 0. ✓OPENFILE "Stock.dat" FOR RANDOM, then SEEK "Stock.dat", Address and GETRECORD "Stock.dat", Current. ✓WHILE Current.ItemCode <> Code AND Current.ItemCode <> 0 AND Count < 500. ✓Address ← (Address + 1) MOD 500, SEEK, GETRECORD and Count ← Count + 1. ✓CLOSEFILE "Stock.dat". ✓IF Current.ItemCode = Code THEN RETURN Address ELSE RETURN -1 (ENDIF, ENDFUNCTION). ✓Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.