Homework 3
Homework 3
Homework 3
Part-A
1. Does the Sequence <23,17,14,6,13,10,1,5,7,12> represents a Max Heap?
ANS1) Yes , the Sequence <23,17,14,6,13,10,1,5,7,12> represents a Max Heap, because
according to structure property of heap , this sequence is having all levels filled and last node is
having only
Ans2) While deleting an element say n from binary tree three cases are concerned
In 3rd case n has two children . let s(n) denote the inorder successor of n .then n is deleted from t by
first deleting s(n) from t and then replacing node n in t by the node s(n).
Out if these 3 , third case is the most complex operation in binary search tree. In all three cases the
memory space of the deleted node n is returned to the AVAIL list.
Replace 12 with 19. Notice, that only values are replaced, not nodes. Now we have two nodes with
the same value
ANS 3) When we insert a new node in a binary search tree, it becomes a terminal node everytime
insertion is done, the newly inserted node is inserted as a leaf node. Eg. Insertion of new element
18 in bst.
Part-B
4. For a binary tree T, the Pre-Order and In-Order traversal sequences are as
Follows:-
Pre-Order: A B L M K N P Q
In-Order: L B M A N K Q P
5. For a binary tree T, the Pre-Order and In-Order traversal sequences are as
Follows:-
Pre-Order: A B E H Q R C D K L M
In-Order: B Q R H E A D L K M C
Following operations:
(b) Deletion from the root : the deletion is done from the root , for that replace the last entered
element with the node root and reheap the heap to get the exact postion of node.
(c)
After reheaping :
1 H 4 11
2 R 0 0
3 17
4 P 0 0
5 B 18 7
6 3
7 E 1 0
8 6
9 C 0 10
10 F 15 16
11 Q 0 12
12 S 0 0
13 0
14 A 5 9
15 K 2 0
16 L 0 0
17 13
18 D 0 0