2.4.16 in Algorithom 4th edition

题目: For N=32, give arrays of items that make heapsort use as many and as few compares as possible.

对于Heap sort, best case 和 wortst case的compare count 都是与nlog(n)量级。不过,二者会有一个contant factor的差别,而且前提条件是所有元素都是互不相同的。

Best case:所有元素都相同,这样compare count ~log(n).

Worst case:所有元素都不相同。

Reference: https://cs.stackexchange.com/questions/18391/best-and-worse-case-inputs-for-heap-sort-and-quick-sort

猜你喜欢

转载自www.cnblogs.com/buyenix/p/10016208.html
今日推荐