CS FundamentalsHardGATE CS (PYQ pattern)

A 10,000-page file is sorted by external merge sort with 21 buffer pages: later passes merge 20 runs at a time, and every pass reads and writes every page. Pass 0 either sorts 21 pages at a time (runs of 21 pages) or uses replacement selection, which produces runs averaging 2 x 21 = 42 pages. How many page I/Os does replacement selection save?

  1. A. 0
  2. B. 40,000
  3. C. 20,000
  4. D. 10,000

Correct answer: C. 20,000

Plain: ceil(10000/21) = 477 runs -> 24 -> 2 -> 1, so 1 + 3 = 4 passes = 80,000 I/Os. Replacement selection: ceil(10000/42) = 239 runs -> 12 -> 1, so 1 + 2 = 3 passes = 60,000 I/Os. Saving one full pass = 2 x 10,000 = 20,000. Longer runs help only when they cut the number of merge passes, which here they do.

More DBMS and SQL questions

Exams that ask this topic