*
The moose likes Java in General and the fly likes Constructing a binary tree from its traversals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Constructing a binary tree from its traversals" Watch "Constructing a binary tree from its traversals" New topic
Author

Constructing a binary tree from its traversals

Keshan Pillay
Greenhorn

Joined: May 21, 2008
Posts: 29
Firstly, thanks to everyone for answering my previous topics, my assignment is going really well. I'm now on part 2, and I need to construct a binary tree from its post-order and in-order traversals. The sample traversals given were:

Inorder traversal: ADHGKLMRUVTW
Postorder traversal: AHDLKGUVRWTM

Can someone please help me with the algorithm to complete this process?

Many thanks,
Yoonsi
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
I will give you a clue from which you can deduce the algorithm easily



Thanks and Regards
Keshan Pillay
Greenhorn

Joined: May 21, 2008
Posts: 29
Hey thanks for the reply. I can't say that your "clue" helped me very much, I already had the tree, but I should have mentioned that. But I managed to get it in the end, so thanks anyway!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
Well done How did you do it? Other people can learn from your example.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Constructing a binary tree from its traversals
 
Similar Threads
When do i say that a binary search tree is unique?!
Is it possible to generate Binary Tree from the expression given in Inorder?
Jquery: Target column text
Recursive / Non-Recursive Function
tree datastructure algorithm