in reply to Reducing HoH to AoA
What you have is an adjacency list representation of a graph, and it looks like you want to find all the connected components of that graph and put them into a list. If that is so, then the second example is ok, since you can get to all the nodes by following the links from 'lineitem'.
If you see a problem with the second example, perhaps you are looking for the strongly connected components of a graph, with each element of a component connected to every other component of the graph.
The easiest way to approach this is to use the perl module Graph:
use Graph::Directed; $G = new Graph::Directed; # ... add vertices, edges @S = $G->strongly_connected_components; # Returns the strongly connected components @S of the # graph $G as a list of anonymous lists of vertices, # each anonymous list containing the vertices #belonging to one strongly connected component.
-Mark
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Reducing HoH to AoA
by dragonchild (Archbishop) on Apr 01, 2004 at 16:35 UTC |