• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Tree Question  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following numbers:
50 25 70 10 37 60 90 30 40

Did I get it right? Here is the tree:

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I take it you were given the tree before figuring the order of the numbers? If so, I believe you are correct.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm given those numbers and I have to make a tree.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 60142
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!