Professional Documents
Culture Documents
Assingment 7
Assingment 7
GROUP
OF INSTITUTIONS
45
STEP 2 : Insert 39
As 39 is smaller than 45, so insert it as the root node of the left subtree .
45
39
45
39 56
STEP 4 : Insert 12.
12 is smaller than 45 and 39, so it will be inserted as a left subtree of 39.
45
39 56
12
45
39 56
12
34
45
39 56
12 78
34
45
39 56
12 78
34
STEP 8 : Insert 10.
10 is less than 45 and 39 and 12 , so it will be inserted as the left subtree
of 12 .
45
39 56
12 78
10 34
STEP 9 : Insert 89.
89 is greater than 45 and 56 and 78 , so it will be inserted as the right
subtree of 78 .
45
39 56
12 78
10 89
34
39 56
STEP 11 : Insert 67.
67 is greater than 45 and 56 but smaller than 78 , so it will be inserted
as the left subtree of 78 .
45
39 56
12 54 78
STEP 12 : Insert 81 .
32 is less than 45 and 39 and greater than 12 and less than 34 , so it will
be inserted as the left subtree of 34 .
45
39 56
12 54 78
10 34 67 89
81
32
STEP 13 : Insert 5.
5 is less than 45 and 39 and 12 and 10 , so it will be inserted as the left
subtree of 10
45
39 56
12 54 78
10 34 67 89
5 81
32
STEP 14 : Insert 9 .
9 is less than 45 and 39 and 12 and 10 and greater than 5 , so it will be
inserted as the right subtree of 5 .
45
39 56
12 54 78
10 34 67 89
5 81
32
STEP 15 : Insert 70 .
70 is greater than 45 and 56 but less than 78 and greater than 67 , so it
will be inserted as the right subtree of 67 .
45
39 56
12 54 78
10 34 67 89
5 70 81
32
9
STEP 15 : DELETE 81 .
45
39 56
12 54 78
10 34 67 89
5 70
32
STEP 16 : DELETE 12 .
45
39 56
12
32 54 78
10 34 67 89
5
70
STEP 17 : DELETE 5 .
45
2)a) Create a binary search tree using the following data
elements 81,63,90,99,54,72,85,39,100,9,95,45,27,98,18,96, and
post order traversal and pre order traversal
=> STEP 1 : INSERT 81 .
STEP 2 : INSERT 63 .
STEP 5 : INSERT 54 .
STEP 6 : INSERT 72 .
STEP 2 : Insert 80 .
20 80
STEP 3 : Insert 55 .
20 55 80
STEP 4 : Insert 15 .
15 20 55 80
15 20 80 116
STEP 6 : Insert 39 .
55
15 20 39 80 116
STEP 7 : Insert 76 .
55
15 20 39 76 80 116
15 20 39 116 124
76 80
STEP 10 : Insert 48 .
55 103
15 20 39 48
116 124
76 80
STEP 11 : Insert 200 .
55 103
15 20 39 48
116 124 200
76 80
STEP 12 : Insert 98 .
55 103
15 20 39 48
116 124 200
76 80 98
15 20 39 48
116 124 175 2
76 80 98
STEP 14 : Insert 235 .
55 103 175
15 20 39 48
200 235
116 124
76 80 98
STEP 15 : Insert 28 .
55 103 175
15 20 28 39 48
200 235
116 124
76 80 98
28 55 103 175
15 20
200 235
39 48
116 124
76 80 98
15 20
200 235
39 48
114 116 124
76 80 98
15 20
200 235
39 48
114 116 124 132
76 80 98
STEP 18 : Insert 164 .
28 55 103 175
15 20
200 235
39 48
114 116 124 132
76 80 98
15 20
200 235
39 48
114 116
76 80 98
132 164
103
28 55 124 175
39 48