You are on page 1of 9

ASSIGNMENT NO.

03

CSE 2050

(DATA STRUCTURE)

SUBMITTED TO: SUBMITTED


BY:
MS.GITIKA MAM NAVNEET
GOYAL ROLL
NO:25
SECTIO
N: E6803
(PART A)
\
Ans1-- In this case one of thenode that is 6 has a right child 7 which is greater than 6. Therefore
it is not a Max Heap.
2
3

1
17
4

6 13 10 1

5 7 12

Ans2: In can be divided into two stages: (a)


Search for a node to remove.
(b) If the node is found, then again there are three cases.

Case I: N has no children.. Example


Case II:. Then N is deleted from T by simply replacing the location of N in P(N) by the location
of the only child of N. Example , remove 18 from BST.

Case III:. 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).
6
25
66

15 50

33

44

From the above BST we remove 25 and the resulting BST is shown below.
60
60

33 66
25 33

15 50
50 66

44
15

Ans3: When we insert a new node in the binary search tree then that node becomes terminal
node of the tree.
Suppose we have the sequence is 14,10,17,12,11,20,18,25,8,22,23 then the binary search tree
will be

14
4

17
18 20 25
10

8 12

11

22

23

The left subtree and now compare 13 with 10. Since 13 is greater than 10 so go to the left subtree
and now compare 13 with 12. Since 13 is greater than the 12 so move to the right side of node 12
as it is empty therefore insert the element 13 as the right child of node 12. From the figure below,
it is clear that the inserted node is the terminal node in the binary search tree.

14
4

10
17

8 12
20

18
11 13
25

22
(PART B)
2
3
Ans4: To draw the Binary tree following is the procedure:
(a)The root of the tree T is obtained by choosing the first node in its preorder. Therefore A is the
root node.
(b)The left child of this node is obtained as follows. First we use the inorder of T to find the
nodes in the left subtree T1 of A. Thus T1 consist of the nodes L,B and M. Then the left child of
A is obtained by using the first node in the preorder of T1. Thus the B is the left child of A.
Repeat the above process with each new node, we will finally obtained the tree as shown.
A

B K

N P

L M

Q
44

Ans:
5-- A

B
C

E
D

H K

Q
L
R
(a) The height of tree is 6
(b) The internal nodes are B, C, E ,D ,H ,K ,Q ,L ,M.
(c) The post order transversal is : B ,Q ,R ,H ,E ,D ,L ,M ,K ,C ,A

Ans: 6 The following sequence <70, 15, 50,5, 12 ,35, 10> represents max heap and is shown as

70

15 50

5 12 35 10

(a)Insert of element 25 ITEM at the end of heap so that heap is still a complete tree, but not
necessarily a heap.
ii) Then let ITEM rise to its appropriate place in tree, so that it remain a heap.

70

25 50

15 12 35 10

5
(b)Deletion from root: Suppose H is heap with N elements, and suppose we want to delete
the root R of H. This is accomplished as follows.
(i)Assign the root R to some variable ITEM.
(ii)Replace the deleted node R by the last node L of H so that H is still a complete tree, but not
necessarily a heap.
(iii)(Reheap) Let L sink to its appropriate place in H so that H is finally a heap.
So finally the heap is

50

25
35

15 12 10

(c)Insertion of element 75: i) First adjoining ITEM at the end of heap so that heap is still a
complete tree, but not necessarily a heap.
ii) Then let ITEM rise to its appropriate place in tree, so that it remains a heap.

75

70 50

15 12 35 10

5
Ans: 7

B C

D
E F

H K L

P Q

You might also like