Data Structures | Heap | Question 12
The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap is.
(A) a
(B) b
(C) c
(D) d
Answer: (A)
Explanation:
32, 15, 20, 30, 12, 25, 16
After insertion of 32, 15 and 20
32
/ \
15 20
After insertion of 30
32
/ \
15 20
/
30
Max Heap property is violated, so 30 is swapped with 15
32
/ \
30 20
/
15
After insertion of 12
32
/ \
30 20
/ \
15 12
After insertion of 25
32
/ \
30 20
/ \ /
15 12 25
Max Heap property is violated, so 25 is swapped with 20
32
/ \
30 25
/ \ /
15 12 20
After insertion of 16
32
/ \
30 25
/ \ / \
15 12 20 16



