Question

In: Computer Science

prove it's correct or not. A particular version of MERGESORT breaks the array into three equal...

prove it's correct or not.

A particular version of MERGESORT breaks the array into three equal parts, recursively sorts the first two parts, merges them, recursively sorts the last part, and merges it with the already merged parts one and two. This MERGESORT has the same worst-case running time as the standard version.

Solutions

Expert Solution

Yes It's correct the merge sort that you mentioned is called as 3 - way Merge Sort has same worst-case running time as the standard 2 way merge sort .

Proof :

We can do Proof using how to build recurrence Relation for both standard and 3 way merge sort and then we can see that after solving we get same complexity or not

In Normal merge sort we have

1. Divide array into halves

2. Sort those halves

3. Merge It

Here Merge takes O(n) time

We get Recurrence Relation as

T(n) = 2 T ( n/2 ) + n  

Now Similarly we have 3 way merge sort

Steps

1. We divide array in 3 parts where each part has n/3 elements

2. Now we sort first two and merge them

3. Then we sort the third part and merge with it with merged part we get in Step 2

Here Lets see how we can build similar Recurrence Relation

The running time to merge first two parts is n/3 + n/ 3 for the call to Merge(L1,L2) = 2n/3

Now we are merging n/3 and 2n/3 so time needs for Merge ( Merge(L1,L2) , L3 )   =

Hence Total time = 5n/3 = same as O(n)

So we get recurrence relation is

T(n) = 3 T( n/3 ) + n

Now We can solve it using Master Theorem

we have nlog33 = n = f(n)

So it is case 3 of the Master Theorem

Hence we get Time complexity as O ( nlogn ) which is same as standard merge sort .

This is how we can proof how 3 way merge sort has same complexity of O( nlogn)

If u like the answer do Upvote it and have any doubt ask in comments

Thank You


Related Solutions

Prove it's correct or wrong. A particular version of PARTITION runs in logarithmic time but produces...
Prove it's correct or wrong. A particular version of PARTITION runs in logarithmic time but produces splits where all elements go to the same side of the pivot every time. QUICKSORT based on this PARTITION has the same worse-case running time as the standard version.
Prove or disprove the following statement: If a hyperbolic triangle has three equal angles then its...
Prove or disprove the following statement: If a hyperbolic triangle has three equal angles then its sides are also equal to each other.
Major federal equal employment opportunity laws have attempted to correct social discrimination toward particular groups of...
Major federal equal employment opportunity laws have attempted to correct social discrimination toward particular groups of workers, called protected classes. Defined broadly, these include individuals of a minority race, women, older people, and those with physical or mental disabilities. Separate federal laws cover each of these classes. Review the timeline of the federal laws in the Content Area and read about each law. Choose one of the federal laws and briefly summarize it, include when it took effect, the implications...
2. Winning the jackpot in a particular lottery requires that you select the correct three numbers...
2. Winning the jackpot in a particular lottery requires that you select the correct three numbers between 1 and 2828 and, in a separate​ drawing, you must also select the correct single number between 1 and 3232. Find the probability of winning the jackpot. 3. Winning the jackpot in a particular lottery requires that you select the correct five numbers between 1 and 4040 ​and, in a separate​ drawing, you must also select the correct single number between 1 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT