All mock tests are FREE till 31 December — register to save your progress

Suppose there are six files F1, F2, F3, F4, F5, F6 with corresponding sizes 150 KB, 225 KB, 75 KB, 60 KB, 275 KB and 65 KB respectively. The files are to be stored on a sequential device in such a way that optimizes (average) access time. In what order should the files be stored?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. F4, F6, F3, F1, F2, F5

Explanation

On a sequential (tape-like) device, reaching any file means physically passing over every file stored ahead of it, so the time to reach file k is proportional to the sum of the sizes of all files placed before it. If every file is accessed with roughly equal probability, the total access time is minimised by the classic 'shortest job first' scheduling rule: placing the smallest files first keeps the cumulative size small for as many of the subsequent files as possible. Sorting by increasing size gives F4 (60), F6 (65), F3 (75), F1 (150), F2 (225), F5 (275), i.e. F4, F6, F3, F1, F2, F5, option (ii); storing largest-first would instead maximise, not minimise, the average time to reach a typical file.

More Database Management Systems questions