Optimal merging of different data sets or files.
Optimal merge pattern is a greedy method to merge two or more files in the minimum possible time.
To achieve our objective, we start with the two smallest files.
In the next step, we merge the next two smallest files,
including the file that we merged in the previous step.
And, do the same till we get the only one file.
For e.g. suppose we have four files f1, f2, f3 & f4 with sizes 5, 7, 3 & 8 respectively.
Step 1 : Merge f3 (size = 3) & f1 (size = 5), we get f31 (size = 8).
Step 2 : Merge f2 (size = 7) & f4 (size = 8), we get f24 (size = 15).
Step 3 : Merge f31 (size = 8) & f24 (size = 15), we get f3124 (size = 23).