跳转至

External Sorting

引入

Why can’t we simply do quicksort on a disk?

To get a[i] on:

  • internal memory – \(O(1)\)
  • hard disk
    1. find the track;
    2. find the sector;
    3. find a[i] and transmit.

原始做法

alt text

Given 10,000,000 records of 128 bytes each, and the size of the internal memory is 4MB. How many passes we have to do?

Answer: 1 + log(320 runs) = 1 + 9

进阶

k-way merge

这种做法旨在减少pass式子中的底数。

alt text

但是这要求\(2k\)条磁带。

减少磁带