Question:

is divided into smaller chunks that can fit into memory In

Last updated: 11/16/2023

is divided into smaller chunks that can fit into memory In

is divided into smaller chunks that can fit into memory In this phase we read the input data sequentially and write the chunks to temporary files 1 7 Merging Phase The sorted temporary files are merged together in a way that minimizes the number of passes In this phase data is read from the temporary files and written into a final output file To calculate the cost of performing this modified external merge sort you can break down the costs into these phases Intermediate Sorting Phase Each of the temporary files created in the initial splitting phase is sorted in memory For each file you read its content into memory sort it and write the sorted data back to a new temporary file Sequential Reads You mentioned that 8 sequential reads are free and that the cost of 8 sequential reads is 1 You ll want to count how many sets of 8 sequential reads are needed in each phase initial splitting intermediate sorting and merging For any leftover reads you can apply the cost of single reads Sequential Writes Sequential writes are never free You mentioned that the cost of N writes is always 2N So count the total number of writes in each phase and calculate the cost accordingly Here s a simplified example to illustrate how to calculate the cost Suppose you have an external merge sort with Input size 80 pages Memory can hold 10 pages Number of temporary files created in the initial splitting phase 8 Number of temporary files created in the merging phase 2 1 Initial Splitting Phase D Sequential Reads 10 reads per file x 8 files 80 reads D Sequential Writes 10 writes per file x 8 files 80 writes 2 Intermediate Sorting Phase Assuming each sorted file fits in memory Sequential Reads 1 read per file x 8 files 8 reads Sequential Writes 2 writes per file x 8 files 16 writes 4 Merging Phase