can i do this by using approach that first i will make a heap using all the elements in all the arrays and then apply heapsort…if yes,what will be the time complexity for that?
Please answer this
Also answer this…Sir hasnt teach how to make priority queue and this kind of implementation which he has used in this example…then how will i understand this…
Yes this can be one of the approach! time complexity will be O(NlogN) where N is the total number of elements in all k arrays.
priority queue will be a normal minheap as after inserting all elements you need to pop smallest present element and add it to your final merged array!
this can be done by:
priority_queue<int,vector,greater > minheap;
which will be the better approach which the sir has used or nlogn?
You can compare the time and space complexity to judge better approach!
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.