The minimum number of record movements required to merge five files A (with records), B (with records), C (with records), D (with records) and E (with records) is:
View worked solution
Answer: A
This problem can be solved using the Optimal Merge Pattern algorithm, which uses a greedy approach similar to Huffman coding. To minimize the total number of record movements, we repeatedly merge the two smallest files at each step.
The initial file sizes are: {5, 10, 15, 20, 25}.
- Step 1: Merge the two smallest files of sizes and .
New file size = .
Cost of this merge = .
Remaining files: {15, 15, 20, 25}. - Step 2: Merge the two smallest files of sizes and .
New file size = .
Cost of this merge = .
Remaining files: {20, 25, 30}. - Step 3: Merge the two smallest files of sizes and .
New file size = .
Cost of this merge = .
Remaining files: {30, 45}. - Step 4: Merge the remaining two files of sizes and .
New file size = .
Cost of this merge = .
The total minimum number of record movements is the sum of the costs of all merge operations:
Free practice · Your answers on this page are not saved.
