Preorder traversal of binary tree


Concept

1.Visit the root.
2.Visit the left subtree.
3.Visit the right subtree.
Note :
Root and left children are visted from top to bottom stepwise.
On the other hand,right children of nodes are visited from bottom to top stepwise.
This is exactly what preorder traversal demands.
Below example will make things more clear.
Preorder traversal : ABCDEFG


More


Non recursive implementation



No comments:

Post a Comment