Merge k sorted arrays using heaps

can u plzz explain and show me the implementation of this question

@ynikhil1999 hey nikhil we will not allowed to share any implementation with student we can debug your code
and there is a video in which by taught the logic of this problem.

then where should I go…to know its code…?
when I didn’t get the logic of this problem…how can I even start its code?

@ynikhil1999 nikhil In video bhaiya is also explain the logic based upon the logic you should write code.

yeahhhh…but i am not smart enough to implement…so plzz be kind enough to help me out

@ynikhil1999 hey nikhil this will work
Create an result[] of size n*k.
Create Min-Heap of type HeapNode.( HeapNode- Every Node will store the data and the list no from which it belongs).
Now take one element from each of the K list and create HeapNode object and insert into min-Heap.
Extract the minimum Node from the min-Heap, insert the data into result array.
The extracted node will also contain the list to which it belongs, insert the next element from that list into min-Heap.
If any point of time any list gets over, insert +∞ into min-Heap.
Keep repeating until all the K list gets over.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.