Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tree and graph data structures in ruby [closed]

Tags:

ruby

tree

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?

like image 471
Dty Avatar asked Nov 19 '11 14:11

Dty


1 Answers

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).

like image 152
KL-7 Avatar answered Oct 06 '22 01:10

KL-7