Binary Tree Traversals ?


Traversing is the process of passing through every node exactly once in a binary tree. Traversing is also  called as visiting. There are 3- ways of traversing techniques.

1. preorder

2. Inorder

3. postorder

Preorder : In pre order traversal a root node is followed by its left sub tree and right sub tree.

    1.    Go to root node

    2.    Traversal the left sub tree

3.    Traversal the right sub tree

binary tree

O/P: ABCDEFGH

Inorder : In order traversal a root node is in between its left sub tree and right sub tree.

    1.    Traverse the left sub tree.

    2.    Process the root node.

    3.    Traverse the right sub tree.
binary tree


O/P: CBAEFDDG

Post Order:  In post order the left sub tree is traversed first and the right sub tree is traversal and then node is traversed . In this traversal the node is after its left and right sub tree.

    1.    Traverse the left sub tree.

    2.    Traverse the right sub tree.

3.    Process the root node.
binary tree


O/P:CBFEDGA


Related

Data Structures 7012388360382434914

Post a Comment

emo-but-icon

item