ON
DATA STRUCTURE
SUBMITTED BY-SURENDRA
D3804A15
10806601
Part-A
1. 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
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
R QHEBLMKDCA
ROOT
14
INFO LEFT RIGHT
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
Ans …
4. Cons3ider the algebraic expression E= (2x + y) (5a – b)3
(A)..
(B)..
ANS. *+*2xy^-5ab3
Part-B
Case a (info,left,right,root,loc,par)
a. If left[loc]=null and right[loc]=null, then:
Set child:=null
Else if left[loc]!= left then
Set child=left[loc]
Else
Set child=right[loc]
[end of structure]
b. If par!=null then
If loc=left[par] then
Set left[par]=child
Else
Set right[par]=child
[End of structure]
Else
Set root=child
c. Return
Case_b(info,left,right,root,loc,par)
a. Find suc and parsuc
Set ptr=right[loc] and save=loc
Repeat while left[ptr]!=null
o Set save=ptr and ptr=left[ptr]
o End of loop
Set Suc=ptr and parsuc=save
b. [delete inorder successor using procedure]
Call case_a(info,left,right,root,suc,parsuc)
c. [replace node N by its inorder successor]
If par!=null then:
o If loc=left[par] then
o Set left[par]=suc
Else
o Set right[par]=suc
End of if structure
Else
Set root=suc
d. Set left[suc]=left[loc] and
Right[suc]=right[loc]
e. Return
Del(info,left,pirht,root,avail,item)
a. Call find(info,left,right,root,item,loc,par)
b. If loc=null then write ITEM not in tree; and exit
c. If right[loc]!=null and left[loc]!=null
Call case_ b
Else
Case_ a
d. Set left[loc]=avail and avail=loc
e. Exit.
11 9 7 15 14 8 10 13
Ans.
7. Illustrate the process of Insertion in binary Search tree by
considering suitable example.
Ans.
EXAMPLE: - Suppose we have a binary search tree and suppose
ITEM=20 is given. Then for insertion we follow the following
process:-
1. Compare ITEM=20 with the root 34, of the tree T. Since 20<34,
proceed to the left child of 36, which is 16.
2. Compare ITEM=20 with 16, since 20>16, proceed to the right
child of 16, which is 28.
3. Compare ITEM =20 with 28, since 20< 28 proceed to the left of 28
which is 18.
4. Compare ITEM=20 with 17, since 20>17, and does not have a
right child, insert 19 as the right child of 17.