You are on page 1of 1

Question 4 [6 points] You are given the following array A which represents a max-Heap:

Index i: 1 2 3 4 5 6 7 8
A[i]: 20 18 16 4 10 3 5 3

1. (2 points) Draw the corresponding binary tree, and then give the sequence of keys in pre-
order, in-order and post-order traversals.
20
Draw the tree:

4 !o s }
1

20,18/43,10
6/3,5
'
pre-order traversal: ,

in-order traversal: 3,4 , 8,10 , 20,3 , 16,5


post-order traversal: 3,4 ,
10,10 , 3,5 , 16,20

2. (2 points) Write the content of the array A after performing the deletion of the maximum
element (removeMax()).

Index i: 1 2 3 4 5 6 7
* 16
A[i]: 18 10 16 4 3 35

41135 's

3. (2 points) Write the content of the array A after performing the insertion of key 19 to the
original max-Heap A, which is given on the top of this page.

Index i: 1 2 3 4 5 6 7 8 9
A[i]: 2019 16 1810 3 5 3 4
20

if \l6 20

41 to 5 's it \l6
's
st ,
=) n'to 's

}
'

tent
COPYRIGHT MOUMTLAGAN
4

You might also like