1. 程式人生 > >2.4.16 in Algorithom 4th edition

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