I'm reading CLRS and had some problem with the exercise 6.5-8.
Give an O(n lg k)-time algorithm to merge k sorted lists into one sorted list, where n is the total number of elements in all the inputs lists. (Hint: use a min0heap for k-way merging.)
The solution is, as everybody says,
1) build a k-element min-heap using the first element of the k lists,
2) extract-min() to get the smallest element from the heap and append it to the result list,
3) pick the next element from the same list as the one we just extracted from the heap. Insert it into the heap and goto 2).
I can understand the time is O(n lg k), but I don't get the correctness of the choice in step 3). It seems obvious but is there some formal proof?