Heapify

 After insertion we perform correction from last to first element and after deletion we perform correction from first to last element. Heapify is method to convert any array to correct head. We can apply heapify anytime in the array. This is the best way to correct the heap.

Let us take an example of array and convert it to a heap.

    Array[] = { 5, 10, 30, 20, 35, 40, 15}


    Select the last parent and make it heap


    Select node before it and correct it


    Select node before it and correct it


    Now we reached the first node so this is Final Heap

    Time Complexity: O(n)

Comments

Popular posts from this blog

Insertion/Deletion in 2-3 Tree