How to build a Min-Max Heap in O(n) time complexity?
问题 I found the topic of min-max heap on Wikipedia. I was wondering if there is any way of building this min-max heap in O(n) . I know you can do this with both min heap and max heap, but I'm not sure what would be the approach for this. Inserting an element takes O(log n) time complexity and I feel like this kind of tree can't be build more efficiently than O(n log n) . 回答1: Yes, it can. In your build-heap loop, you simply call TrickleDown , just like you would with a min heap or a max heap.