# Deleting in a Heap

### Procedure :

Copy the last element to root i.e index 1.

Shift the root element to last element of heap.

Set i as 1 (root) and j as 2*i (left child of root).

Perform the following until j < size - 1.

Find which of the child is greater.

Set j to point on that child.

If the child element (j) is greater than parent element (i), swap them.

Set i as j and j as 2*j after each iteration.

**By calling the same function n times, heap sort can be implemented.**

Last updated