Uploaded by salma25102001

DS Sheet(4) Student Version-Binary Tree

advertisement
Sheet Duration 2 -3 Weeks
Question to be Explained during section time, Highlighted by Yellow.
stions Homework – handed over as a report.
SHEET FOUR
1. Given a set of input representing the nodes of a binary tree, write a non-recursive algorithm
that must be able to output the three traversal orders.
2. What is a Binary Search Tree (BST)? Make a BST for the following sequence of numbers.
45, 36, 76, 23, 89, 115, 98, 39, 41, 56, 69, 48 Traverse the tree in Preorder, Inorder and
postorder.
3. What are expression trees? Represent the following expression using a tree. Comment on
the result that you get when this tree is traversed in Preorder, Inorder and postorder.
(a-b) / ((c*d)+e)
4. Taking a suitable example explains how a general tree can be represented as a Binary
Tree.
5. Draw the expression tree of the following infix expression. Convert it in to Prefix and
Postfix expressions. ((a + b)+ c * (d + e)+ f )* (g + h)
6. Two Binary Trees are similar if they are both empty or if they are both nonempty and left
and right sub trees are similar. Write an algorithm to determine if two Binary Trees are
similar.
7. Construct a binary tree whose nodes in inorder and preorder are given as follows:
Inorder : 10, 15, 17, 18, 20, 25, 30, 35, 38, 40, 50
Preorder: 20, 15, 10, 18, 17, 30, 25, 40, 35, 38, 50
8. Let a binary tree ‘T’ be in memory. Write a procedure to delete all terminal nodes of the
tree.
9. Consider the algebraic expression E = (5x+z) (3a-b)2
(i) Draw the expression tree corresponding to E
(ii) Find the scope of exponential operator i.e. the subtree rooted at the
exponential operator.
Download