I have received a homework that requires me to Merge K sorted lists having a total of N elements into a single sorted list efficiently. The methods that I have stumbled upon are to use a Min-heap to sort the elements from the K lists or use a Divide and Conquer approach(pair-wise merging). The comments in this thread tells that the Divide and Conquer approach takes Time complexity of O(NK), whereas the Min-heap one takes O(N log K) and both have the same space complexity. I also visited many other threads, but i can't get a clear picture.
Doubts & Questions:
- Many other sites told that both the Divide & Conquer and Min-Heap approach have a Time complexity of O(N log K). Is it true or False?
- Is the Space complexity of both the approaches same? If not, how do they differ?
- Why if the Min-heap approach better than Divide & Conquer for lists of varying length?
- I also found that you can use a Priority Queue to solve the problem. How does it compare to these?