473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to build a BSt from tree traversals

3
hi
how do we build a binary search tree when post order and inorder tree traversals are given to u....and how do we make use of creat root and create tree templates in your existing code???
Feb 27 '08 #1
3 2262
manontheedge
175 100+
do you know what a binary search tree is? or how to traverse it ( in any order ) on paper?
Feb 27 '08 #2
zeah
3
do you know what a binary search tree is? or how to traverse it ( in any order ) on paper?
yes i know how all traversals work on paper..but im not able to write code for generating it from the traversals....
here is a desciption of how u build a tree from postorder and inorder traversals on papaer...

Postorder: D C B K J I A
Inorder: C D B A I J K
from post order we take the last node(A)
now A becomes the root.Search A in inorder. whereever u find A, the nodes left to A becomes the left tree(C D B) and the nodes on right forms the right tree(I J K).
Same way we take the next root from post order i.e I now then look for I in the in order.now I becomes the right node of A and J K goes to form right tree of I.
Then we go for next root i.e J and look for J in inorder...and so

so can any1 help me out with the codin of ths.....
Feb 29 '08 #3
make a recursive func.. call it repeatedly. make it do what u are saying recursively...make two arrays to store the inorder and postorder...
then pick last ele as temp. Then temp is root node.
then search for temp index in inoder array..all ele on left will be made left tree of the temp...and right will be right.
call the func again on the left tree and the right tree and so on till u get null.........

I THINK this shud work. :/
Nov 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Carl | last post by:
Dear friends, What are the best options for implementing fast and efficient trees in Python? The typical trees that I'm thinking of are those used by the finance industry to price different...
4
by: Henry Jordon | last post by:
I have everything pretty much done but I need to fix something in my coding. I want to be able to enter strings such as "love", "hate", "the", etc. but am unable to figure how to do this. I have...
0
by: wcsnyder | last post by:
For those who didn't catch this announcement on the moderated group, I am pleased to announce the initial release of RPSL (Rapid Prototyping Shared Library). RPSL is a set of bash scripts and...
22
by: delraydog | last post by:
It's quite simple to walk to the DOM tree going forward however I can't figure out a nice clean way to walk the DOM tree in reverse. Checking previousSibling is not sufficient as the...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
2
by: graphicsxp | last post by:
Hi, I have the following records stored in the database : TableName: Folder { FolderID, FolderName, TopLevel} TableName: FolderRelationship { ParentID, ChildID} This describes a folder...
1
by: RashmiKalra2222 | last post by:
How to create a tree if its Inorder/Postorder/PreOrder traversals are given input. Plz tell Algorithm and Program in C for the same.
1
by: Federico | last post by:
Hi I've some trivial question: for exercise I want to parse a string that like this: "x -34 + 65 * 96 = 102" now if I had this ("(25+24)/2") is extremely easy to have a result but I want to...
2
by: APEJMAN | last post by:
Hi, would you please guide me with this question? suppose we have a tree with at least 3 nodes containing unique integer values. I want to draw an example tree that justifies my answer and write out...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.