
q8
The formula you should use to determine how many iterations (merge passes) are necessary in a multiway merge sort with limited memory is:
Formula:
Where:
- = Number of pages in memory.
- = Number of runs you can merge in one pass (because 1 page is reserved for output).
- = Initial number of runs (after the first pass of reading and sorting blocks).
Example from the image:
-
Memory pages:
-
Sorted runs:
-
Runs merged at a time:
-
Passes:
Final Answer:
Use:
to calculate the number of merge iterations needed.
q9
q 10
Number of runs =ceiling(576/M) Number of runs ⇐ M−1