[PTA] ADS-2016 Assignment 4 2-2

We can perform BuildHeap for leftist heaps by considering each element as a one-node leftist heap, placing all these heaps on a queue, and performing the following step: Until only one heap is on the queue, dequeue two heaps, merge them, and enqueue the result. Which one of the following statements is FALSE? (3分)

[PTA] ADS-2016 Assignment 4 2-2_第1张图片


        主要想法是,用分治思想来建左式堆。

        第1轮:大小为1的堆两两合并

        第2轮:大小为2的堆两两合并

        第3轮:大小为4的堆两两合并

        ……

         以此类推。


        由合并堆的时间复杂度为O(logN),我们很容易写出它的递推式:

        T(N) = 2 T(N/2) +  O(logN)

        将该式展开得到:

        T(N) = O(N/2 log2^1 + N/2^2 log2^2 + …… +N/2^k log2^k),其中N = 2^k。

       继续计算上式,可以把log的指数拿下来:T(N) = N*sigma( i/2^i)右式可由乘公比错位相消求得为常数,极限2.

        所以建堆的时间复杂度为O(N),而不是O(NlogN)


附图:1~15按顺序插入斜堆

[PTA] ADS-2016 Assignment 4 2-2_第2张图片


你可能感兴趣的:([PTA] ADS-2016 Assignment 4 2-2)