This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 161 Summer 2009 Homework #3 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than an error in addition of points, please include with your homework a detailed explanation of which problems you think you deserve more points on and why. We reserve the right to regrade your entire homework, so your final grade may either increase or decrease. Problem 1 [5 points] What really is important for on-disk sorting approaches is less about memory usage and more about how many times were going to have to visit the disk. In practice, Merge-Sort is the algorithm that is amenable to on-disk sorting. De- pending on the data set and implementation, Quicksort can also be feasible. The other algorithms have varying issues described below that tend to account for too many disk accesses. As mentioned above, Merge-Sort is very good for this since once weve split the data down to small enough chunks to process in memory, we only need to process on those chunks until we need to do the final merger of the larger chunks. Even the merger of the larger chunks is fairly disk friendly since its just a traversal of data one element at a time starting at the beginning of a chunk of memory. If you look at the unix/linux sort function, which does on disk sorting, Merge-Sort is used. Algorithms like Insertion-Sort and bubble sort that make multiple passes over all of the data tend to perform poorly because theyre accessing all of the data over and over again and must continually read that data off disk and get very little reuse of the data that is...
View Full Document
- Summer '09