Binary Tree
A tree whose elements have at most 2 children is called a binary tree. Since each element in a binary tree can have only 2 children, we typically name them the left and right child.
A Binary Tree node contains following parts.
- Data
- Pointer to left child
- Pointer to right child
Depth First Traversals:
(a) Inorder (Left, Root, Right) :
4 2 5 1 3
(b) Preorder (Root, Left, Right) :
(b) Preorder (Root, Left, Right) :
1 2 4 5 3
(c) Postorder (Left, Right, Root) :
(c) Postorder (Left, Right, Root) :
4 5 2 3 1
Breadth-First or Level Order Traversal:
Breadth-First or Level Order Traversal:
its traversing like row by row.
1 2 3 4 5
1 2 3 4 5
Comments
Post a Comment