12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

282 Chap. 8 File Processing <strong>and</strong> External SortingThere are generally two approaches <strong>to</strong> minimizing disk accesses. The first is<strong>to</strong> arrange information so that if you do access data from secondary memory, youwill get what you need in as few accesses as possible, <strong>and</strong> preferably on the firstaccess. File structure is the term used for a data structure that organizes datas<strong>to</strong>red in secondary memory. File structures should be organized so as <strong>to</strong> minimizethe required number of disk accesses. The other way <strong>to</strong> minimize disk accesses is<strong>to</strong> arrange information so that each disk access retrieves additional data that canbe used <strong>to</strong> minimize the need for future accesses, that is, <strong>to</strong> guess accurately whatinformation will be needed later <strong>and</strong> retrieve it from disk now, if this can be donecheaply. As you shall see, there is little or no difference in the time required <strong>to</strong> readseveral hundred contiguous bytes from disk as compared <strong>to</strong> reading one byte, sothis strategy is indeed practical.One way <strong>to</strong> minimize disk accesses is <strong>to</strong> compress the information s<strong>to</strong>red ondisk. Section 3.9 discusses the space/time tradeoff in which space requirements canbe reduced if you are willing <strong>to</strong> sacrifice time. However, the disk-based space/timetradeoff principle stated that the smaller you can make your disk s<strong>to</strong>rage requirements,the faster your program will run. This is because the time <strong>to</strong> read informationfrom disk is enormous compared <strong>to</strong> computation time, so almost any amoun<strong>to</strong>f additional computation <strong>to</strong> unpack the data is going <strong>to</strong> be less than the disk readtime saved by reducing the s<strong>to</strong>rage requirements. This is precisely what happenswhen files are compressed. CPU time is required <strong>to</strong> uncompress information, butthis time is likely <strong>to</strong> be much less than the time saved by reducing the number ofbytes read from disk. Current file compression programs are not designed <strong>to</strong> allowr<strong>and</strong>om access <strong>to</strong> parts of a compressed file, so the disk-based space/time tradeoffprinciple cannot easily be taken advantage of in normal processing using commercialdisk compression utilities. However, in the future disk drive controllers mightau<strong>to</strong>matically compress <strong>and</strong> decompress files s<strong>to</strong>red on disk, thus taking advantageof the disk-based space/time tradeoff principle <strong>to</strong> save both space <strong>and</strong> time.Many cartridge tape drives (which must process data sequentially) au<strong>to</strong>maticallycompress <strong>and</strong> decompress information during I/O.8.2 Disk DrivesA Java programmer views a r<strong>and</strong>om access file s<strong>to</strong>red on disk as a contiguousseries of bytes, with those bytes possibly combining <strong>to</strong> form data records. Thisis called the logical file. The physical file actually s<strong>to</strong>red on disk is usually nota contiguous series of bytes. It could well be in pieces spread all over the disk.The file manager, a part of the operating system, is responsible for taking requestsfor data from a logical file <strong>and</strong> mapping those requests <strong>to</strong> the physical location

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!