-1

The question:

Merge k sorted arrays each with n elements into a single array of size nk in minimum time complexity. The algorithm should be a comparison-based algorithm. No assumption on the input should be made.

So I know about an algorithm that solves the problem in nklogk time complexity as mentioned here: https://www.geeksforgeeks.org/merge-k-sorted-arrays/.

Though, my question is can we sort in less than nklogk, meaning, the runtime is o(nklogk).

So I searched through the internet and found this answer: Merge k sorted arrays of size n in O(nk) time complexity

Which claims to divide an array of size K into singletons and merge them into a single array. But this is incorrect since one can claim that he found an algorithm that solves the problem in sqrt(n)klogk which is o(nklogk) but n=1 so we sort the array in KlogK time which doesn't contradict the lower bound on sorting an array.

So how can I contradict the lower bound on sorting an array? meaning, for an array of size N which doesn't have any assumptions on the input, sorting will take at least NlogN operations.

4
  • 1
    "So how can I contradict the lower bound on sorting an array?": which lower bound you want to contradict? And why do you think it should be contradicted?
    – trincot
    May 22, 2022 at 9:14
  • lower bound on sorting an array, meaning, for an array of size N which doesn't have any assumptions on the input, sorting will take at least NlogN operations. May 22, 2022 at 9:53
  • Yes, that is the lower bound. So my question is why do you want to contradict it?
    – trincot
    May 22, 2022 at 10:01
  • "my question is can we sort in less than nklogk" No we can't. "So I searched through the internet and found this answer" The answer is not comparison based. May 22, 2022 at 11:58

1 Answer 1

0

The lower bound of n log n only applies to comparison-based sorting algorithms (heap sort, merge sort, etc.). There are, of course, sorting algorithms that have better time complexities (such as counting sort), however they are not comparison-based.

7
  • Yes, the algorithm should be comparison-based, I didn't mention it. May 22, 2022 at 10:14
  • 2
    Counting sort only has a "better" complexity under extra assumptions (namely, that the number of distinct possible values is known in advance and not too large). If you allow extra assumptions, then even comparison-based sorting algorithms can have better complexity. As a degenerate example, under the assumption "the input is already sorted", you can have a O(1) complexity ;-)
    – Stef
    May 22, 2022 at 10:50
  • @linuxbegginer Well, in the case of comparison-based sorting algorithms, it's not possible to contradict the lower bound since it has been mathematically proven.
    – jgh99
    May 22, 2022 at 13:41
  • Where exactly it has been mathematically proven? Plus, no assumptions have been made regarding the numbers appearing in the array. So no counting sort or any sort that use assumptions on the input. May 22, 2022 at 16:52
  • @linuxbegginer You can find the proofs online. A quick googling gives me this and this.
    – jgh99
    May 23, 2022 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.