I'm having a hard time finding tree data structures to use in ruby. Are there some well known ones I can look into? My requirements are simple. I want to create a tree (or maybe it's a graph) and find the distance between some of the nodes. For example, I might have a tree/graph like the following
A
/ \
B-----C
/ \ \
D E F
I want to be able to find the distances between the root node (A) and all the other nodes. So the distance between (A, B) should be 1, between (A, E) is 2, etc. Even though from node (A) you can get to (C) via (A, B, C), the length should still just be 1 since there is a direct path from (A, C).
Is there a tree/graph gem I can use in ruby for this?
Have a look at gratr gem and its documentation. It provides classes for representing various types of graphs and basic algorithms for finding distance between their vertices (see
Distance
module).