Unit V-Trees
Unit V-Trees
Trees
Topics
• Introduction
• Properties of trees
• Binary search tree
• Tree traversal
• Decision tree
• Prefix codes and Huffman coding, cut sets,
• Spanning Trees and Minimum Spanning Tree,
• Kruskal’s and Prim’s algorithms,
• The Max flow- Min Cut Theorem (Transport network).
Introduction
Introduction
Properties of trees
Properties of trees
Properties of trees
50 is greater than 45 but smaller than 79 and 55. So, it will be inserted as a left subtree of 55.
Binary search tree( Assignment)
• Construct binary search tree
21,28,14,18,11,32,25,23,37,27,5,15,19,30,12,26,
Tree traversal
• Traversing or visiting each node of a tree
3 ways of Tree Traversal
• Preorder traversal: root- left- right
• Inorder traversal: left-root-right
• Postorder traversal: left-right-root
Tree traversal
• Preorder traversal: root- left- right
• First root node is visited after that the left subtree is traversed
recursively, and finally, right subtree is recursively traversed.
• As the root node is traversed before (or pre) the left and right
subtree, it is called preorder traversal.
• Each node is visited before both of its subtrees.
Step 1 - Visit the root node
Step 2 - Traverse the left subtree recursively.
Step 3 - Traverse the right subtree recursively.
Preorder Traversal A → B → D → E → C → F → G
Tree traversal
• Postorder traversal: left-right –root
• Step 1 - Traverse the left subtree recursively.
• Step 2 - Traverse the right subtree recursively.
• Step 3 - Visit the root node.
Postorder Traversal D → E → B → F → G → C
→A
Tree traversal
Inorder traversal :left- root –right
• Step 1 - Traverse the left subtree recursively.
• Step 2 - Visit the root node.
• Step 3 - Traverse the right subtree recursively.
Inorder Traversal:D → B → E → A → F → C → G
Tree traversal
Construct a binary tree from given inorder and preorder traversals
• Inorder :b d f h k m p t v m
• Preoder: b f d k h v w t m
Arithmetic expressions
• Standard: infix form
(A+B) * C – D/ E
• Fully parenthesized form (in-order & parenthesis):
(((A + B) * C) – (D / E))
• Postfix form (reverse Polish notation):
AB + C *D E / -
• Prefix form (Polish notation):
- *+AB C / D E
Decision Tree