Tree structures and graphics in ruby

I find it difficult to find tree-like data structures for use in ruby. Are there any known ones that I can look at? My requirements are simple. I want to create a tree (or maybe a graph), and find the distance between some nodes. For example, I may have a tree / graph as shown below.

A / \ B-----C / \ \ DEF 

I want to find the distances between the root of node (A) and all other nodes. Thus, the distance between (A, B) should be 1, between (A, E) equal to 2, etc. Even if from node (A) you can go to (C) via (A, B, C), the length should only be 1, since there is a direct path from (A, C).

Is there a tree / graph that I can use in ruby ​​for this?

+6
source share
1 answer

See gratr gem and documentation . It provides classes for representing various types of graphs and basic algorithms for finding the distance between their vertices (see Distance ).

+2
source

Source: https://habr.com/ru/post/901892/


All Articles