When the input is much too large to fit into memory, we have to do external sorting instead of internal sorting. One of the key steps in external sorting is to generate sets of sorted records (also called runs) with limited internal memory. The simplest method is to read as many records as possible into the memory, and sort them internally, then write the resulting run back to some tape. The size of each run is the same as the capacity of the internal memory.
Replacement Selection sorting algorithm was described in 1965 by Donald Knuth. Notice that as soon as the first record is written to an output tape, the memory it used becomes available for another record. Assume that we are sorting in ascending order, if the next record is not smaller than the record we have just output, then it can be included in the run.
For example, suppose that we have a set of input { 81, 94, 11, 96, 12, 99, 35 }, and our memory can sort 3

本文介绍了Donald Knuth提出的置换选择排序算法,该算法用于外部排序。当内存不足以一次性存储所有数据时,通过每次读取内存容量大小的数据进行内部排序,然后输出最小值并释放内存,继续读取下一个数据。文章提供了算法的详细解释、C++代码实现以及样例测试。
最低0.47元/天 解锁文章
755

被折叠的 条评论
为什么被折叠?



