3,892 views
2 votes
2 votes
Given a set of sorted files f1,f2,f3,f4,f5 of lengths 99,27,71,199,259 we need to merge these files into a single sorted file Using Optimal Merge Pattern.

1 Answer

Best answer
4 votes
4 votes

According to optimal merge pattern we take two minimal and merge it so given sequence is:

f1 99
f2 27
f3 71
f4 199
f5 259

we arrange sequence in ascending order

f2, f3, f1, f4, f5

M1: Merge f2 and f3 :: 27+71 = 98

M2: Merge  M1 and  f1 :: 98+99 = 197

M3: Merge M2 and f4:: 197+199 = 396

M4 Merge M3 and f5:: 396+259 = 655

selected by

Related questions

2 votes
2 votes
2 answers
1
Ali Jazib Mahmood asked Aug 18, 2017
1,394 views
To merge 2 files of size m and n it takes m + n time What will be the optimal time Complexity to merge the files of size 10, 15, 40, 70, 75 and 80?
0 votes
0 votes
2 answers
2
0 votes
0 votes
3 answers
4
Deeptimittal97 asked Jul 6, 2017
10,187 views
What will be the time complexity to obtain optimal merge pattern to merge files using greedy technique?