问题 Creating a heap takes O(n) time while inserting into a heap (or priority queue) takes O(log(n)) time. Taking n inputs and inserting them into the priority queue, what would be the time complexity of the operation? O(n) or O(n*log(n)). Also, the same result would hold in case of emptying the entire heap too (i.e. n deletions), right? 回答1: If you have an array of size n and you want to build a heap from all items at once, Floyd's algorithm can do it with O(n) complexity. See Building a heap.