Pre Order Traversal In Binary Tree

Pre Order Traversal In Binary Tree

  1. Its NLR ordered traversal.
  2. The order goes this way:
    1. N: visit the node
    2. L: Traverse the left sub tree.
    3. R: Traverse the right sub tree.
  3. 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
    1. On completing the traversal we get the pre order if we follow the bolded nodes.
    2. Pre Order: 1 , 2 , 4 , 5 , 3 , 6 , 7

Comments

Popular

Traversal In A Binary Tree - Tree -3

Tree data structure - 2