External Sort
---------------
M blocks available for an operation
PAGES(R)
PAGES(R) < M,
Cost of sort = Reading R completely once, sort and output, PAGES(R)
--------
PAGES(R) >> M
External sort:
Step 1: While there are more pages in R: Read in groups of M pages,
sort and write to disk
Read R once fuly and written R once fully -> 2*PAGES(R)
Step 2: Merge from each block and output.
PAGES(R) = 8 M=4
Step 1: Cost = 16 pages
Resulted in 2 sorted groups (4 pages wide total)
Step 2: Cost = Read R once more, 8 pages and output.
-----------------
Ex:
PAGES(R) = 1,000
M = 20
-------
Step 1: cost = 2,000 pages
1,000/20 = 50 sorted groups
-------
Step 2: cost = 2,000 pages (read/write)
ceil(50/20) = 3 sorted groups
---------
Step 2: merge and output cost = 1,000 pages
Cost = 5,000 pages
====================
PAGES(R) = 1,000
M = 100
Step 1: cost = 2,000 pages
1,000/100 = 10 sorted groups
-------
Step 2: read/merge and output, Cost = 1,000 pages