我试图理解以下锦标赛排序(替换选择),它是一种用于在主存储器中进行排序的排序算法。
任何解释这是如何工作的?
Keep two heaps in memory, H1 and H2
read B-2 pages of records, inserting into H1; #B is buffer size
while (records left) {
m = H1.removemin();
put m in output buffer;
if (H1 NOT empty)
read in a new record r (use 1 buffer for input pages);
if (r < m)
H2.insert(r);
else
H1.insert(r);
else
H1 = H2;
H2.reset();
start new output run;
}
H1.output();
start new run;
H2.output();