Question

Optimal Merge Pattern - We saw from MergeSort that merging two sorted files together (one size...

Optimal Merge Pattern - We saw from MergeSort that merging two sorted files together (one size m and one size n) took O(m+n) time. When merging multiple sorted files together, the merge can be accomplished by repeatedly merging sorted files in pairs. For example X1, X2, X3 are three sorted files of length 30, 20 and 10. There are multiple ways to merge them two-at-a-time (with the appropriate costs):


(X1 merge X2) merge X3 X1 merge (X2 merge X3) (X1 merge X3) merge X2
cost=50 cost=60 cost=60 cost=30 cost=40 cost=60
total cost=110 total cost=90 total cost=100


Different pairings require different amounts of computing time. How would you solve this problem to find the optimal way to merge the files two-at-a-time. Prove the required properties of the problem and for your solution approach.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For merging multiple sorted files,

suppose that we have n file x1,x2,.....,xn having size s1,s2,......,sn respectively.

for merging optimally we use greedy approach,In which

we first create stack of files in which we have inserted file in descending order that means we first push file which has highest size and after that push file which has second highet size and like that push all files in stack so that stack's top contain file which has lowest size.

Now pop two files from stack and merge them and then calculate size of resulting file and put it in stack and after that sort stack array in descending order.

again pop two files from stack and repeat above process.

After repeating this process many times finally you get resultant file with minimum cost.

if you have any query then feel free to ask in comment.

Add a comment
Know the answer?
Add Answer to:
Optimal Merge Pattern - We saw from MergeSort that merging two sorted files together (one size...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • When we have two sorted lists of numbers in non-descending order, and we need to merge...

    When we have two sorted lists of numbers in non-descending order, and we need to merge them into one sorted list, we can simply compare the first two elements of the lists, extract the smaller one and attach it to the end of the new list, and repeat until one of the two original lists become empty, then we attach the remaining numbers to the end of the new list and it's done. This takes linear time. Now, try to...

  • please write me this program in C language Review UW files from the Internet can contain...

    please write me this program in C language Review UW files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View View View - Word Terme MOHAMMED MUNTHER MOH Enable Editing Task # 3: Consider two integer arrays x and y of same size n with values: Xo, X1, X3,..., Xe1 and yo, yi, ya..... Yn-1 Write a function merge that receives array x and y and their size. It then returns...

  • Suppose we are given two sorted arrays (nondecreasing from index 1 to index n) X[1] ·...

    Suppose we are given two sorted arrays (nondecreasing from index 1 to index n) X[1] · · · X[n] and Y [1] · · · Y [n] of integers. For simplicity, assume that n is a power of 2. Problem is to design an algorithm that determines if there is a number p in X and a number q in Y such that p + q is zero. If such numbers exist, the algorithm returns true; otherwise, it returns false....

  • Exercise 2 Linear Programming 1.         The Scrod Manufacturing Co. produces two key items – special-purpose Widgets...

    Exercise 2 Linear Programming 1.         The Scrod Manufacturing Co. produces two key items – special-purpose Widgets (W) and more generally useful Frami (F). Management wishes to determine that mix of W & F which will maximize total Profits (P). Data                                                                      W      F             Unit profit contributions                     $ 30   $ 20             Demand estimates (unit/week)               250      500             Average processing rates – each product requires processing on both machines (units/hour)                                     Machine #1                        2          4                                        Machine #2                ...

  • Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In...

    Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...

  • STA2221 examples on CI & Testing of Hypothesis Name MULTIPLE CHOICE. Choose the one alternative that...

    STA2221 examples on CI & Testing of Hypothesis Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answer the question Provide an appropriate response. 1) Find the critical value,te for 0.99 and n-10. A) 3.250 B) 3.169 1.833 D) 2.262 2) Find the critical value to forc=0.95 and n=16. A) 2.947 B) 2.602 2120 D) 2.131 3) Find the value of E, the margin of error, for A) 1.69 B) 0.42 0.99, n=16 and s=2.6. C)...

  • Amazon to Competition: We Will Crush You! Amazon to Employees: We Will Churn You! Globally, Amazon...

    Amazon to Competition: We Will Crush You! Amazon to Employees: We Will Churn You! Globally, Amazon is one of the largest and most successful companies in any industry. Technological innovation has contributed to its success, as has its employee acquisition practices, which are exceptionally high. The question is what has allowed this company to thrive and maintain its success? This activity is important because it shows how companies like Amazon hire based on personality and individual differences. Such companies place...

  • Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART...

    Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{    int day;    int month;    int year; }; /** This structure is to store the size of the box and it...

  • The following ANOVA model is for a multiple regression model with two independent variables: Degrees of            Sum of                 Mean Source           Freedom            Squares              ...

    The following ANOVA model is for a multiple regression model with two independent variables: Degrees of            Sum of                 Mean Source           Freedom            Squares                Squares       F       Regression            2                    60 Error                   18                 120 Total                   20                 180 Determine the Regression Mean Square (MSR): Determine the Mean Square Error (MSE): Compute the overall Fstat test statistic. Is the Fstat significant at the 0.05 level? A linear regression was run on auto sales relative to consumer income. The Regression Sum of Squares (SSR) was 360 and...

  • Summary should briefly analyze the central problems and issues of the case and provide some analysis...

    Summary should briefly analyze the central problems and issues of the case and provide some analysis and suggestions. Thank you. Lean Initiatives and Growth at Orlando Metering Company It was late August 2002 and Ed Cucinelli, vice president of Orlando Metering Company (OMC), sat in his office on a late Saturday morning. He had come in to prepare for some strategic planning meetings that were scheduled for the upcoming week. As he noticed the uncommon silence in the building, Ed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT