I have m arrays, each array has a length n. Each array is sorted. I want to create a single array of length m * n containing all the values of previous arrays (including duplicate values), sorted. I have to combine these arrays.
I think the optimal time complexity is m * n * log (m)
Here's a sketch of the algorithm ..
I am creating an H support array from lenth m containing all the values of the first element of each array.
Then I sort this array (m log m) and move the min value to the output array.
Then I replace the moved value with the next one from the array that was made. In fact, I do not replace it, but I insert it into the desired (sorted) position. I think it will take a magazine.
And I repeat this for all m * n values ... therefore m * n * log m
My question is ... can you come up with a more efficient algorithm? If mnlogm is actually optimal, can you at least think of a simpler and more elegant algorithm?
sorting arrays algorithm complexity-theory data-structures
francesco delvinis
source share