What are the k-sorted lists 1, ..., k.
Let A be the name of the combined sorted array.
For each list i, pop v off i and press (i, v) in the mini-heap. Now the heap will contain pairs of values ββand a list identifier for the smallest entries in each of the lists.
Until the heap is empty, pop (i, v) from the heap and add v to A Select the next off list i item (if it's not empty) and put it in a heap.
On the heap, n added and deleted. A heap contains no more than k elements at each time step. Therefore, the runtime is O(n log k) .
source share