Cs502 Assignments
Cs502 Assignments
We need to insert the node 35 into the given max heap and apply the heapify procedure to maintain the
max heap property.
38
/ \
13 24
/ \ / \
1 7 5 NULL
The new node 35 is inserted at the next available position in the tree (as a child of 24) to maintain the
complete binary tree structure:
38
/ \
13 24
/ \ / \
1 7 5 35
Apply Heapify (Bottom-Up)
We now compare the inserted node 35 with its parent 24 and swap them because 35 > 24. The tree
becomes:
38
/ \
13 35
/ \ / \
1 7 5 24
Next, compare 35 with its parent 38. Since 35 < 38, no further swaps are needed, and the max heap
property is restored.
38
/ \
13 35
/ \ / \
1 7 5 24
Question 2:
Given below is an unsorted array. You are required to sort the following given array step by step,
using Merge Sort (ascending order). You are required to correctly fill the empty cells given below using
the divide and conquer strategy of merge sort algorithm.
Solution.
Divide the Array
----------------
| |
---
| |
----- -----
| | | |
[27, 38]
[3, 43]
Final Diagram: