aspose file tools*
The moose likes Beginning Java and the fly likes Tree Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Tree Question" Watch "Tree Question" New topic
Author

Tree Question

Steven Alvarez
Ranch Hand

Joined: Nov 01, 2006
Posts: 66
I have the following numbers:
50 25 70 10 37 60 90 30 40

Did I get it right? Here is the tree:

Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
I take it you were given the tree before figuring the order of the numbers? If so, I believe you are correct.
Rich Wright
Greenhorn

Joined: Oct 08, 1999
Posts: 17
Were you given the tree and need to come up with the sequence? If so, it depends because there are tow general approaches to a traversal sequence, depth-first traversal or breadth-first traversal. Is the approach you need to use specified?
Steven Alvarez
Ranch Hand

Joined: Nov 01, 2006
Posts: 66
I'm given those numbers and I have to make a tree.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Given the numbers and asked to insert them into a binary tree that remains sorted as you insert it, that will be the final structure.

It just so happens that if you were asked to keep the tree balanced or to not worry about keeping it balanced it would end up in the same structure. If the numbers had been in a different order, and you were asked to rebalance the tree after each insert, it would be a bit more trouble to figure out.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Originally posted by Steven Alvarez:
I'm given those numbers and I have to make a tree.
How far have you got? Please show us what you are using. Once you have got your head round the concept of a tree, they are really easy to create.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tree Question