I want to write an algorithm of time O(n*lgk) for the merge of k sorted arrays into one sorted array, where n is the total number of elements of all the input arrays.
Could you give me a hint how we could do this?
EDIT: I wrote the following algorithm:
Algorithm(L) // L=[L1, L2, L3, ...., Lk]
list=LNEW;
for (i=1; i<=k; i++){
H[i]=L[i][1];
}
BUILD-HEAP(H);
j=1;
while (j<n){
LNEW[j]=H[1];
yes=0;
m=1;
while (m<=k and L[m][j]!=NULL and L[m][j+1]!=NULL and yes!=1){
if (H[1]==L[m][j]){
H[1]=L[m][j+1];
yes=1;
Heapify(H);
}
j=j+1;
}
Could you tell me if it is right?