• edited by
25,185 views
48 48 votes

The minimum number of record movements required to merge five files A (with $10$ records), B (with $20$ records), C (with $15$ records), D (with $5$ records) and E (with $25$ records) is:

  1. $165$
  2. $90$
  3. $75$
  4. $65$

5 Answers

Best answer
47 47 votes
Arrange files in increasing order of records:

$\overset{\boxed5}{\text{D}}\quad \overset{\boxed{10}}{\text{A}}\quad\overset{\boxed{15}}{\text{C}}\quad\overset{\boxed{20}}{\text{B}}\quad\overset{\boxed{25}}{\text{E}}$


$\qquad\qquad\qquad\qquad\color{blue}{75}$

$\qquad\qquad\quad\color{blue}{30}\qquad\qquad\qquad\color{blue}{45}$

$\qquad\quad\color{blue}{15}\qquad\overset{\boxed{\text{C}}}{15}\qquad\qquad\overset{\boxed{\text{B}}}{20}\qquad\overset{\boxed{\text{E}}}{25}$

$\quad\overset{\boxed{\text{D}}}{5}\qquad\overset{\boxed{\text{A}}} {10}$

No. of movements $=15+30+45+75=165.$

Correct Answer: $A$
• edited by
13 13 votes

No of movements=15+30+45+75=165

6 6 votes

Try to implement it like Huffman coding.

Sorted files 5,10,15,20,25

1) merge min two -- 15,15,20,25 | merges=5+10=15

2) next two -- 30,20,25 -> reordering -- 20,25,30 | merges = merges+15+15=15+(15+15) = 45

3) next two -- 45,30 --> reordering -- 30,45 | merges= merges+ 20+25 = 45+(20+25) = 45+45= 90

4) last two -- 75 | merges = merges+45+30 = 90+(45+30) = 90+75 = 165

so, 165 is the answer

6 6 votes

This question is based on the concept of Optimal Merge Pattern (OMP), which is actually the same greedy logic used in Huffman coding.

 

We are given 5 files:  

- A = 10 records  

- B = 20 records  

- C = 15 records  

- D = 5 records  

- E = 25 records  

 

We want to merge them into one file with the minimum number of record movements.  

The cost of merging two files = sum of their sizes (since every record must be copied once).

 

Optimal Merge Pattern

The greedy rule:  

- Always merge the two smallest files first.  

- Put the merged file back into the set.  

- Repeat until only one file remains.  

 

It ensures larger files are not copied repeatedly

 

Similarity with Huffman coding

Huffman coding works in the exact same way:  

- Always combine the two smallest frequency symbols.  

- Make a parent node with weight equal to the sum of the two.  

- Repeat until a single root remains.  

 

The total weighted path length of the Huffman tree = minimum cost of encoding.  

 

So in both cases:  

- File sizes ↔ frequencies  

- Merge cost ↔ parent node weight  

- Total movements ↔ total weighted path length  

 

This is why the mathematics is identical.

 

Given question:

Files: 5, 10, 15, 20, 25

 

Steps:  

1. Merge 5 + 10 = 15 (cost = 15)  

2. Merge 15 + 15 = 30 (cost = 30)  

3. Merge 20 + 25 = 45 (cost = 45)  

4. Merge 30 + 45 = 75 (cost = 75)  

 

Total cost = 15 + 30 + 45 + 75 = 165

• edited by
2 2 votes
Sort the files: 5, 10, 15, 20, 25.
Merge the smallest two records 15, 15, 20, 25
Merge 30, 20, 25
Sort 20, 25, 30
Merge 45, 30
75. So C is the answer
Answer:
Position:
Show:

Related questions

43 43 votes
6 answers 6 answers
17.0k
17.0k views
Kathleen asked Sep 23, 2014
17,039 views
The number of binary strings of $n$ zeros and $k$ ones in which no two ones are adjacent is$^{n-1}C_k$$^nC_k$$^nC_{k+1}$None of the above
25 25 votes
6 answers 6 answers
7.1k
7.1k views
go_editor asked Feb 28, 2018
7,090 views
Consider the following solution to the producer-consumer problem using a buffer of size 1. Assume that the initial value of count is 0. Also assume that the testing of co...
24 24 votes
6 answers 6 answers
8.7k
8.7k views
Kathleen asked Sep 23, 2014
8,708 views
A certain processor provides a 'test and set' instruction that is used as follows:TSET register, flagThis instruction atomically copies flag to register and sets flag to ...
36 36 votes
5 answers 5 answers
18.7k
18.7k views
Kathleen asked Sep 23, 2014
18,729 views
Booth's coding in $8$ bits for the decimal number $-57$ is:$0-100+1000$$0-100+100-1$$0-1+100-10+1$$00-10+100-1$