What is the time complexity of a k-way merge?

流过昼夜 提交于 2019-12-25 00:30:30

问题


I'm trying to understand the time complexity of a k-way merge using a heap, and although there is a plethora of literature available on it, I can't find one that breaks down the analysis such that I can understand.

This Wikipedia article claims that "In an O(k) preprocessing step the heap is created using the standard heapify procedure". However, heap insertion is O(log(n)) and find-min is O(1). We start by inserting the first elements of each array into the heap. This takes ∑log(i) time, i = 0 to k - 1 or O(klog(k)) time, that refutes the Wikipedia complexity analysis. (actually O(log(k!)))

We then remove the min element, and insert the next element from the array where the min element originally came from. This takes O(1) + O(log(k)) time, which we repeat n - 1 times. Overall time:

O(klog(k)) + O(n - 1) + O((n - 1)log(k)) ≅ O(klog(k)) + O(n) + O(nlog(k))

Wikipedia claims: "the total running time is O(n log k)". How is that?

来源:https://stackoverflow.com/questions/53137556/what-is-the-time-complexity-of-a-k-way-merge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!