开发者

Heap sort analysis

In the analysis of heap sort we know that one of the ways to perform heap sort is in two phases.

  1. Create a heap i.e., max or min priority queue.
  2. Remove the maximum/minimum from priority queue until all elements have been removed

Suppose there are N elements. For phase 1 the number of comparisons is 2N and for one removal the number of comparisons is 2lgN so for N removals it is 2NlgN comparisons. So total number of comparisons is 2N + 2NlgN.

This is my understanding. The book I am reading is Algorithms analysis by Wesis which says:开发者_如何转开发

In the second phase, the ith deletemax uses at most 2(floor(log i)) comparisons, for a total of at most 2NlogN - O(N) comparsions (assuming N >= 2). Consequently in the worst case, there are at most 2NlogN - O(n) comparisons for heap sort.

My questions are

  1. How did the author conclude that in the second phase, the ith deletemax uses at most 2(floor(logi)) comparisons?

  2. How did the author come up with a total of 2NlogN - O(N)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜