RE: [Boost-Users] Re: Tree Object Needed!
Hossein Haeri wrote:
Does the method you mentioned work for my problem in which there is no ordering? If yes, please explain it in more detail (with an example). Trees are generally used with ordered sequences, aren't they? If your data are not ordered, then how do you propose to insert them into the tree? What, well, order would they appear in the tree?
If you provide a little more information about the problem domain, we can help you figure out the best container to use. -- Jim
On Mon, 9 Jun 2003, Jim.Hyslop wrote:
Hossein Haeri wrote:
Does the method you mentioned work for my problem in which there is no ordering? If yes, please explain it in more detail (with an example). Trees are generally used with ordered sequences, aren't they? If your data are not ordered, then how do you propose to insert them into the tree? What, well, order would they appear in the tree?
Not to put words into Hossein's mouth...but I'm going to. It sounds like he's looking for a data structure that represents a plain old tree - no ordering, just the parent/child relationships. A family tree (rooted at a single person) would be a good example. I think this was discussed before on this mailing list, The (obvious) solution was to use a graph, and if necessary, add code that constrains it to satisfy the tree properties. Apologies if I'm wrong. :P -Ryan ------------------------------- "The most is how much I front. It's...it's the amount." -MC Frontalot, 'Front the Most'
Not to put words into Hossein's mouth...but I'm going to. It sounds like he's looking for a data structure that represents a plain old tree - no ordering, just the parent/child relationships. A family tree (rooted at a single person) would be a good example.
That's exactly what I meant! But my concrete problem is some hierarchy in Civil Engineering.
I think this was discussed before on this mailing list, The (obvious) solution was to use a graph, and if necessary, add code that constrains it to satisfy the tree properties.
Apologies if I'm wrong. :P Not only you weren't wrong, but also you were
And how can I find the related emails? Can you remember the topic for those? perfectly right! Thanks, --Hossein __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com
On Mon, 9 Jun 2003, Hossein Haeri wrote:
The (obvious) solution was to use a graph, and if necessary, add code that constrains it to satisfy the tree properties.
And how can I find the related emails? Can you remember the topic for those?
I went back and looked, and in Kasper Peeters' response to your original email, he pointed to a generic n-ary tree (imho a good solution): http://www.damtp.cam.ac.uk/user/kp229/tree/#structure His email is here: http://article.gmane.org/gmane.comp.lib.boost.user/3564/match=+kasper+peeter... I'd agree with some of the other responses, though...the basic, five-line solution is extremely simple, and it works. If you need extra operations like tree traversals or search, they may depend on your specific problem enough that you'd benefit from a custom-tailored solution. -Ryan ------------------------------- "The most is how much I front. It's...it's the amount." -MC Frontalot, 'Front the Most'
I went back and looked, and in Kasper Peeters' response to your original email, he pointed to a generic n-ary tree (imho a good solution):
http://www.damtp.cam.ac.uk/user/kp229/tree/#structure Thanks a lot. I think you have given me the right stuff.
His email is here:
http://article.gmane.org/gmane.comp.lib.boost.user/3564/match=+kasper+peeter... You made to doubt in my memory, as I don't remember getting such an email.
I'd agree with some of the other responses, though...the basic, five-line solution is extremely simple, and it works. If you need extra operations like tree traversals or search, they may depend on your specific problem enough that you'd benefit from a custom-tailored solution.
Yes, may be. Thanks again, --Hossein __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com
Jim,
Trees are generally used with ordered sequences, aren't they?
Yes they are, but not in my case!
If your data are not ordered, then how do you propose to insert them into the tree?
Just as knowing where to put them, knowing which node is a parent/child of which other one.
What, well, order would they appear in the tree?
In fact, the tree I want to represent is just a hierarchy. The only fact that I know about this hierarchy is the parent/child relationship. Thanks, --Hossein __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com
From: "Hossein Haeri"
In fact, the tree I want to represent is just a hierarchy. The only fact that I know about this hierarchy is the parent/child relationship.
This still makes it hard to come up with a solution for it, because you don't say what operations are needed on the tree, or how many children there are - although you said _binary_ search tree, but as others have pointed out, with the tree being unordered, it's no longer a search tree, so one may wonder if the binary part is correct, too. Given your current description of what you want, here's one that satisfies it: template<class T> struct tree_node { T data; tree_node *left; tree_node *right; }; This isn't intended to be sarcastic, but rather to point out that so far you've provided way too little information about what you want to do with the tree, to be able to give a meaningful reply (other than the links to present libraries). Regards, Terje
This still makes it hard to come up with a solution for it, because you don't say what operations are needed on the tree, or how many children there are - although you said _binary_ search tree, but as others have pointed out, with the tree being unordered, it's no longer a search tree, so one may wonder if the binary part is correct, too.
I don't know how to get the group to forgive me. Doesn't the group receive all of my answers, while I myself do? I think it was more than a couple of days ago that I did apologize because of that silly mistake. I'm really astonished seeing people still trying to answer my original message, while I have sent several corrections on it. I redo it one time more: EXCUSE ME BECAUSE OF SPEAKING SO CARELESSLY. The container I need is not a binary tree at all.
Given your current description of what you want, here's one that satisfies it:
template<class T> struct tree_node { T data; tree_node *left; tree_node *right; };
I don't think so!
This isn't intended to be sarcastic, but rather to point out that so far you've provided way too little information about what you want to do with the tree, to be able to give a meaningful reply (other than the links to present libraries).
You are right to some extends. This is because I had just considered to watch the tools that I thought to be solved problems to get some idea about how to analyze my problem, and then how to solve it. Wishes, --Hossein __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com
From: "Hossein Haeri"
This still makes it hard to come up with a solution for it, because you don't say what operations are needed on the tree, or how many children there are - although you said _binary_ search tree, but as others have pointed out, with the tree being unordered, it's no longer a search tree, so one may wonder if the binary part is correct, too.
I don't know how to get the group to forgive me. Doesn't the group receive all of my answers, while I myself do? I think it was more than a couple of days ago that I did apologize because of that silly mistake. I'm really astonished seeing people still trying to answer my original message, while I have sent several corrections on it. I redo it one time more: EXCUSE ME BECAUSE OF SPEAKING SO CARELESSLY. The container I need is not a binary tree at all.
Yes, I read your recent posting where you said it was to model a hierarchy, of parent/child. Yet, that doesn't contradict a binary tree structure, depending on the number of children, so I thought that part might still be correct. Anyway, I understand you now may have found something you can use. Regards, Terje
participants (4)
-
Hossein Haeri
-
Jim.Hyslop
-
Ryan Barrett
-
Terje Slettebø