Professional Documents
Culture Documents
Building a heap
Given an unsorted array, the first step is to
build a heap(or max-heap) out of that array so
that elements of the array fulfils the heap
property.
To build a heap out of the given array, the
elements in the given array are considered
one by one.
If an element ARR[i] is greater than its parent,
which is stored at location (i-1)/2, then the
element is swapped with its parent.