Storing Files on Tape
Explore how greedy algorithms help optimize the order of storing files on magnetic tape to minimize access times. Understand how file lengths and access frequencies influence the best ordering strategy. Learn to apply proofs showing sorting by file length or by length-to-frequency ratio leads to minimal expected access cost.
Introduction to storing files
Suppose we have a set of files that we want to store on magnetic tape. In the future, users will want to read those files from the tape. Reading a file from tape isn’t like reading a file from a disk; first, we have to fast-forward past all the other files, and that takes a significant amount of time. Let be an array listing the lengths of each file; specifically, file has length . If the files are stored in order from to , then the cost of accessing the th file is:
Expected cost of accessing a random file
The cost reflects the fact that before we read file we must first scan past all the earlier files on the tape. If we assume for the moment that each file is equally likely to be accessed, then the expected cost of searching for a random file is:
...