Binary Tree
Definition:
A binary tree T is a finite set of nodes with the following properties:
A binary tree T is a finite set of nodes with the following properties:
- Either the set is empty, ; or
- The set consists of a root, r, and exactly two distinct binary trees and , .
- The tree is called the left subtree of T, and the tree is called the right subtree of T.
- They are considered as Ordered subtrees.
- Level i has 2i nodes.
In a tree of height h,
- Leaves are level at h.
- No of leave are 2h.
- No of internal nodes 2h -1.
- No of internal nodes = no of leaves -1
- Total no of nodes = 2h+1 -1 =n
In a tree on n nodes
- No of leaves is (n+1)/2
- height = Log2(n+1)/2
Tree Traversal
- PostOrder Traversal
- PreOrder Traversal
- InOrder Traversal
PostOrder Traversal : In post order tree walks process each node after processing its children.
PreOrder traversal : In preorder tree walk processes each node before processing its children.
Inorder Traversal : Besides preorder and postorder , a third possibilities arises when node is visited between visit to left and right sub tree.
PostOrder : C,B,F ,G E,I,H,D,A
PreOrder : A,B,C,D,E,F,G,H,I
InOrder :B,C,A,F,E,G,D,I,H
Comments
Post a Comment