ASSIGNMENT ON DATA STRUCTURE

SUBMITTED TO- MR. SANJAY SOOD 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

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 M In-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 QHEBLMKDCA 3. Suppose a binary tree is in memory:ROOT 14 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 Ans … INFO H R P B E C F Q S LEFT 4 0 17 0 18 3 1 6 0 15 0 0 0 A K L 5 2 0 13 D 0 0 9 0 0 RIGHT 11 0 0 7 0 10 16 12 0

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.

*+*2xy^-5ab3

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:=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.

6. Create a heap for following series: 11 Ans. 9 7 15 14 8 10 13

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.