《算法導論》課後習題 9.1-1

1.  原題

Show that the second smallest of n elements can be found with n + lg n − 2
comparisons in the worst case. (Hint: Also find the smallest element.)

2. 思路

2.1 利用最小堆

1)首先建立一個最小堆,需要 O(N)時間

2)獲取最小元素,需要O(1)

3)調整剩下的元素組成的最小堆,需要O(lg(N))時間

4)獲取第二個最小元素



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章