Skip to content
Official PYQ · 1999

GATE CS 1999 Q2.20 — Algorithm Design: Greedy Techniques

Explain with AI

The minimum number of record movements required to merge five files A (with 1010 records), B (with 2020 records), C (with 1515 records), D (with 55 records) and E (with 2525 records) is:

Choose one option
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}.

  1. Step 1: Merge the two smallest files of sizes 55 and 1010.
    New file size = 5+10=155 + 10 = 15.
    Cost of this merge = 1515.
    Remaining files: {15, 15, 20, 25}.
  2. Step 2: Merge the two smallest files of sizes 1515 and 1515.
    New file size = 15+15=3015 + 15 = 30.
    Cost of this merge = 3030.
    Remaining files: {20, 25, 30}.
  3. Step 3: Merge the two smallest files of sizes 2020 and 2525.
    New file size = 20+25=4520 + 25 = 45.
    Cost of this merge = 4545.
    Remaining files: {30, 45}.
  4. Step 4: Merge the remaining two files of sizes 3030 and 4545.
    New file size = 30+45=7530 + 45 = 75.
    Cost of this merge = 7575.

The total minimum number of record movements is the sum of the costs of all merge operations:

Total Cost=15+30+45+75=165\text{Total Cost} = 15 + 30 + 45 + 75 = 165

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Greedy Techniques questions