SUPREME KNOWLEDGE FOUNDATI0N
GROUP
OF INSTITUTIONS
NAME : ABHIJIT PAL
UNIVERSITY ROLL NO : 25300121050
UNIVERSITY REG. NO :
212530100110052
STREAM : CSE YEAR : 2nd SEMESTER :
3rd
SUBJECT NAME : Data Structure and
Algorithm
SUBJECT CODE : PCC-CS301
1. a) Create a binary search tree using the
following data elements
45,39,56,12,34,78,32,10,89,54,67,81,5,9,70
and delete 81,12,5. Describe each and every
step.
STEP 1 : Insert 45. Here , 45 is root node .
45
STEP 2 : Insert 39
As 39 is smaller than 45, so insert it as the root node of the left subtree .
45
39
STEP 3 : Insert 56.
As 56 is greater than 45, so insert it as the root node of the right subtree.
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
STEP 5 : Insert 34.
34 is smaller than 45 and 39 but greater than 12, so it will be inserted as
the right subtree of 12 .
45
39 56
12
34
STEP 6 : Insert 78.
78 is greater than 45 and 56, so it will be inserted as the right subtree of
56 .
45
39 56
12 78
34
STEP 7 : Insert 32.
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 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
STEP 10 : Insert 54.
32
54 is larger than 45 and smaller than 56, so it will be inserted as the left
subtree of 56.
45
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 3 : INSERT 90.
STEP 4 : INSERT 99 .
STEP 5 : INSERT 54 .
STEP 6 : INSERT 72 .
STEP 7 : INSERT 85.
STEP 8 : INSERT 39 .
STEP 9 : INSERT 100.
STEP 10 : INSERT 9 .
STEP 11 : INSERT 95 .
STEP 12 : INSERT 45 .
STEP 13 : INSERT 27 .
STEP 14 : INSERT 98 .
STEP 15 : INSERT 18.
STEP 15 : INSERT 96.
POST-ORDER TRAVERSAL :
18 , 27 , 9 , 45 , 39 , 54 , 72 , 63 ,85 ,96 ,98 , 95 ,100 ,99
,90 , 81
PRE-ORDER TRAVERSAL :
81 , 63 ,54 ,39 ,9 ,27 ,18 ,45 ,72 ,90 ,85, 99 ,95 ,98 ,96 , 100
3)a) Insert these number in a B-tree of order 5 from
the following number :
20,80,55,15,116,39,76,124,103,48, 200,98,175,235,
28,114, 132,164
=> Here , m=5
So , Maximum key in one node is :- (m-1 )
=4
And , minimum key in any node except root node is :- (5/2-1)
=1 .
STEP 1 : Insert 20 .
20
STEP 2 : Insert 80 .
20 80
STEP 3 : Insert 55 .
20 55 80
STEP 4 : Insert 15 .
15 20 55 80
STEP 5 : Insert 116 .
15 20 55 80 116
55
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
STEP 8 : Insert 124 .
55
15 20 39 76 80 116 124
STEP 9 : Insert 103 .
55 103
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
STEP 13 : Insert 175 .
55 103
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
STEP 16 : Insert 114 .
28 55 103 175
15 20
200 235
39 48
114 116 124
76 80 98
STEP 17 : Insert 132 .
28 55 103 175
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
28 55 103 124 175
15 20
200 235
39 48
114 116
76 80 98
132 164
103
28 55 124 175
114 116 200
15 20
76 80 98
132 164
39 48
4a) a) Insert these number in a B+-tree of order 5
from the following number :-
20,80,55,15,116,39,76,124,103,48, 200,98,175,235,
28,114, 132,164
5)a) Insert these number into :
i) Max Heap ii)Min Heap
36,89,12,67,56,43,54,98,6,60,94,26 and delete root node from the above
tree. Describe each step