BUILD-MAX-HEAP running time for array sorted in decreasing order
问题 I know that the running time for BUILD-MAX-HEAP in heap sort is O(n) . But, if we have an array that already sorted in a decreasing order, why do we still have O(n) for the running time of BUILD-MAX-HEAP? Isn't it supposed to be something like O(1) ? It's already sorted from the maximum value to the minimum value, so we do not need MAX-HEAPIFY. Is my understanding correct? Could someone please explain it to me? 回答1: You are right. It can of course be O(1) . When you know for sure that your