1. Build min heap with first element of all K arrays.
2. Pick the root of min element and put it in the resultant array.
3. If there are remaining elements in the array,
Put that element at root of min heap and heapify again
4. If all elements are already considered, put INT_MAX and heapify again.
5. Repeat step 2,3,4 for N*K times.
Read full article from Algorithms and Me: Heaps : Merge K sorted arrays each having N elements in sorted array
No comments:
Post a Comment