D3804A15 DS 4
Transcript of D3804A15 DS 4
ASSIGNMENTON
DATA STRUCTURE
SUBMITTED TO- MR. SANJAY SOOD
SUBMITTED BY-SURENDRA D3804A1510806601
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 QIn-Order: L B M A N K Q P
2. 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 MIn-Order: B Q R H E A D L K M C
(a) What is the height of the tree?(b)What are the internal nodes?(c) What is its Post-Order traversal sequence?
(a) The tree height is 5.(b)
(c) Post-Order traversal sequence:- R Q H E B L M K D C A
3. Suppose a binary tree is in memory:-
ROOT14
INFO LEFT RIGHT1 H 4 112 R 0 03 174 P 0 0
5 B 18 76 37 E 1 08 69 C 0 1010 F 15 1611 Q 0 1212 S 0 013 014 A 5 915 K 2 016 L 0 017 1318 D 0 0
Ans …
4. Cons3ider the algebraic expression E= (2x + y) (5a – b)3
(a)Draw the tree T which corresponds to the expression E.(b)Find the Pre-Order of T.
(A)..
(B)..ANS. * + * 2 x y ^ - 5 a b 3
Part-B
5. Illustrate the process of deletion in binary Search tree by considering suitable example.Ans..;
Case a (info,left,right,root,loc,par)a. If left[loc]=null and right[loc]=null, then:
Set child:=nullElse if left[loc]!= left then
Set child=left[loc]ElseSet child=right[loc]
[end of structure]b. If par!=null then
If loc=left[par] thenSet left[par]=child
ElseSet right[par]=child
[End of structure]ElseSet 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=saveb. [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] theno Set left[par]=sucElseo Set right[par]=sucEnd of if structureElseSet root=suc
d. Set left[suc]=left[loc] andRight[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 exitc. If right[loc]!=null and left[loc]!=null
Call case_ b Else
Case_ a
d. Set left[loc]=avail and avail=loce. Exit.
6. Create a heap for following series:
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.