Ads

Pages

Saturday, April 30, 2011

CS301 Assignment # 3 Solution

CS301
Assignment # 3
Solution
 
Question

Consider a binary search tree (BST) that is initially empty. Draw the tree that will result if the following numbers are inserted in the order given below:

13, 3,1,2,4,12,10,5,8,7,6,9,11,14,15,18

 
After making a BST perform the following operations on it.

a) Pre order Traversal

b) Inorder Traversal

c) Postorder Traversal

Solution:

a) Pre Order Traversal

13, 3,1,2,4,12,10,5,8,7,6,9,11,14,15,18

b) Inorder Traversal

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,18

c) Postorder Traversal

2,1,6,7,9,8,5,11,10,12,4,3,18,15,14,13

No comments:

Post a Comment