Tree class

  • Thread starter Mickael Faivre-Macon
  • Start date
M

Mickael Faivre-Macon

Hi,

Is there a tree class in the language or a good lib out there ?
Thanks for your suggestions.
 
M

Mickael Faivre-Macon

Hi Robert,

Thanks for your reply.

What would be the reference class for Ruby ?
For example it is said tat REXML is the reference for managing XML.
Is there such a librairy for trees ?

A lot of lib in the RAA are too specialized (binary trees, avl,
redblack trees, etc)
I am searching for a general tree class.

Mickael.
 
B

Brian Schröder

Hi Robert,

Thanks for your reply.

What would be the reference class for Ruby ?
For example it is said tat REXML is the reference for managing XML.
Is there such a librairy for trees ?

A lot of lib in the RAA are too specialized (binary trees, avl,
redblack trees, etc)
I am searching for a general tree class.

Mickael.

The question should be what you want to do with your tree. You should
pick a datastructure suitable for your problem, there is no tree per
se. It depends on which pointers you need and which structure your
tree should have.

If you just want nodes with children try this "reference implementation"

---
class Node
attr_reader :children

def initialize
@children =3D []
end
end
---

which may or may not suit your needs.

Cheers,

Brian
 
M

Mickael Faivre-Macon

Hi Brian,
The question should be what you want to do with your tree. You should
pick a datastructure suitable for your problem, there is no tree per
se. It depends on which pointers you need and which structure your
tree should have.

My question was simple, the concept of tree is simple too, I don't
want to over complicate the problem. I must assume that there is no
generic tree implementation in Ruby avalaible right now. Okay.
If you just want nodes with children try this "reference implementation"

---
class Node
attr_reader :children

def initialize
@children =3D []
end
end

Sure, this is a good start. I can start by using this.
I was wondering if I had to reinvent the wheel or not.
I guess I have to.

Mickael.
 
B

Brian Schröder

Hi Brian,
The question should be what you want to do with your tree. You should
pick a datastructure suitable for your problem, there is no tree per
se. It depends on which pointers you need and which structure your
tree should have.

My question was simple, the concept of tree is simple too, I don't
want to over complicate the problem. I must assume that there is no
generic tree implementation in Ruby avalaible right now. Okay.
If you just want nodes with children try this "reference implementation= "

---
class Node
attr_reader :children

def initialize
@children =3D []
end
end

Sure, this is a good start. I can start by using this.
I was wondering if I had to reinvent the wheel or not.
I guess I have to.

Mickael.

What I wanted to say, was that most probably you do not have to
reinvent the wheel if you are more specific about your application.
What do you want to achieve: Find elements in a set fast, Have a
datastructure where you can access and delete the smallest element in=20
a fast way, build an index into a sorted array that allows for fast
range searches, draw a natural tree with real leaves onto the computer
monitor, structure a decision diagram, index a text, ....

Depending on what you want to achieve a specialized datastructure is
usefull, but there is no datastructure that can do all things equally
well.

hope to help,

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top