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 access time. In what order should the files be stored?
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 access time. In what order should the files be stored? Correct Answer F4, F6, F3, F1, F2, F5
The correct answer is option 2.
Key Points
Six files are stored in a sequential device. It is like an optimal merge pattern. To get optimum access time, first, sort all the files according to their sizes. For sorting it will take worst case O(N log N) but will give the optimal result. Select the two files which are minimal in size.
Merging files required m + n - 1 comparisons.
Merge
Shortcut Trick
Sort the files based on size in ascending order