Tuesday, June 7, 2016

Convert min Heap to max Heap - GeeksforGeeks

The problem might look complex at first look. But our final goal is to only build the max heap. The idea is very simple – we simply build Max Heap without caring about the input. We start from bottom-most and rightmost internal mode of min Heap and heapify all internal modes in bottom up way to build the Max heap.

The complexity of above solution might looks like O(nLogn) but it is O(n). Refer this G-Fact for more details.