Pre Order Traversal In Binary Tree Its NLR ordered traversal. The order goes this way: N: visit the node L: Traverse the left sub tree. R: Traverse the right sub tree. Lets check with an example. Consider the following example. Visit the node 1 Traverse the left sub tree of node 1 Visit the node 2 Traverse the left sub tree of node 2 Visit the node 4 Traverse the right sub tree of node 2 Visit the node 5 Traverse the right sub tree of node 1 Visit the node 3 Traverse the left subtree of node 3 Visit the node 6 Traverse the right sub tree of node 3 Visit the node 7 On completing the traversal we get the pre order if we follow the bolded nodes. Pre Order: 1 , 2 , 4 , 5 , 3 , 6 , 7
Comments
Post a Comment