Merging K- Sorted Lists using Priority Queue

后端 未结 7 1558
无人及你
无人及你 2021-01-06 18:17

I have been asked in my algorithm class to make a K-way merge algorithm which is of O(nlogk) After searching i found it could be done via making a k length prio

7条回答
  •  攒了一身酷
    2021-01-06 18:34

    You should not here that "n" the total number of nodes over all the list not just one list. In this case the solution is O(n logk). If we mean that we have n node on an average in every list(total of k lists) then it will be O(nk logk)

    Here is an in depth explanation with some code

提交回复
热议问题