Two-Way External Merge Sort
•Each pass we read + write each page in file. •N pages in the file => the number of passes
•
•So total cost is:
•
•
•Improvement: start with larger runs
•Sort 1GB with 1MB memory in 10 passes
•
Input file
1-page runs
2-page runs
4-page runs
8-page runs
PASS 0
PASS 1
PASS 2
PASS 3
9
3,4
6,2
9,4
8,7
5,6
3,1
2
3,4
5,6
2,6
4,9
7,8
1,3
2
2,3
4,6
4,7
8,9
1,3
5,6
2
2,3
4,4
6,7
8,9
1,2
3,5
6
1,2
2,3
3,4
4,5
6,6
7,8