- #1

- 4

- 0

## Homework Statement

We have k >= 1

**sorted**arrays, each one containing n >= 1 elements (all equal length). We want to combine all of them in to a single sorted array with kn elements.

We have a "naive" algorithm: merge the first two arrays, then merge the third array into the result, then merge the fourth array into the result, and so on.

What's the complexity of the naive algorithm, as a function of k and n?

**2. The attempt at a solution**

Assuming k > 1. When comparing first two arrays, worst-case requires (n log n) comparisons.

Adding a third array to the resulting array has a worst-case of (2n log 2n) comparisons.

Similarly, adding a fourth has (3n log 3n) comparisons. This suggests a general worst-case equation for the algorithm: (k-1)n log (k-1)n

I don't think this is right... the next part of the question asks us to talk about a less expensive implementation, but (k-1)n log(k-1)n is already in big theta of n log n, which is plenty efficient.