Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
binary tree,the pre and post order traversal have the same method? is in both methods
#1
When we call pre-order function first the root node is printed and after that left node is printed and then right node is printed. In post-order traversal first left node is printed then right node is printed and then root node is printed.







10

/ \

/ \

5 12

/ \

/ \

3 6



When we call pre-order function on this tree. First pre-order call on node 10. Node 10 is printed. Then we pre-order call on 5 as 5 has both left and right child so 5 is printed. Then pre-order call on node 3. 3 is printed. It check whether 3 has any left child. As 3 has not any left child so it check whether 3 has right child which is not so pre-order function call on 6 . 6 is printed. We check its left child which is null and then its right child which is also null after that pre-order call on node 12 node 12 is print after that we check its left child as left child is null we check right child which is also null.



When we apply Post-order function on this tree. First node 10 is traverse, function check its left node which is 5. 5 also have left node which is 3 as 3 have not any left child neither right child so 3 is printed. Then go to the 5. As 5 have right node so 6 is printed. Then 5 is printed which is the root of both 3 and 6. Then we traverse 10. As 10 has right child so which is 12. we traverse 12 . As 12 have not any left child and right child so 12 is printed and then we traverse 10. In the end 10 is printed.



To see animation of tree traversal, see this link.

Binary Tree Traversals


0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is difference among Binary Tree, Complete Binary Tree and Binary Search Tree? Vuhelper 2 4,339 03-18-2012, 12:47 AM
Last Post: Xpert
  Threaded Binary Tree? in C++ 2012 Vuhelper 0 3,469 01-06-2012, 12:25 AM
Last Post: Vuhelper
  What is the difference b/w Inorder Traversal and Inorder Successor? 2012 Vuhelper 0 1,788 01-06-2012, 12:23 AM
Last Post: Vuhelper
  what is in order successor? in C++ 2012 Vuhelper 0 2,591 01-04-2012, 11:08 PM
Last Post: Vuhelper
  how stack operation proves costly during traversing a tree Vuhelper 0 1,518 01-04-2012, 10:43 PM
Last Post: Vuhelper
  ASCII code is binary numbers of 0 and 1 in C++ 2012 Vuhelper 0 2,278 01-04-2012, 10:41 PM
Last Post: Vuhelper
  why huffman tree is not an AVL tree not how? Vuhelper 0 2,040 01-04-2012, 10:39 PM
Last Post: Vuhelper
  why Hoffman tree is not an AVL Tree? Vuhelper 0 2,121 01-04-2012, 10:33 PM
Last Post: Vuhelper
  AVL tree, It must satisfie the 2 conditions. Vuhelper 0 811 01-04-2012, 10:32 PM
Last Post: Vuhelper
  how to insert a new node on AVL tree using double rotation? Vuhelper 0 2,676 01-04-2012, 10:31 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)