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)獲取第二個最小元素