1.2k views

The elements $32, 15, 20, 30, 12, 25, 16,$ are inserted one by one in the given order into a maxHeap. The resultant maxHeap is

edited | 1.2k views

Just keep inserting elements making sure resulting Tree is nearly Complete.(Heap Property) .

While inserting any node, if you find that  Value of New Node $>$ Value of it's parent, bubble it up to keep Max heap property

edited
Insert each node as the left most leaf and check if it is less than the parent or not, if not then swap it with the parent

32

32
/
15

32
/  \
15  20

Now 30 cannot be inserted as 15's child, so it will be in 15's place with 15 as it's child

32
/  \
30  20
/
15

32
/  \
30  20
/  \
15  12

25 cannot be inserted as 20's child, so it will be in place of 20, with 20 as it's child

32
/  \
30   25
/  \      /
15  12  20

32
/   \
30    25
/  \      /  \
15  12  20  16
Option a is correct just try to insert an element and shift whenever necessary Here shift operation is performed when 30 and 25 is inserted