Representing a Tree in Python

CTO debatem1 at gmail.com
Wed May 13 02:56:50 EDT 2009


> But let me clear the my problem again. I have a graph. and I want to
> find 'shortest path tree' from a root node to several nodes. as a
> example if we have a graph of 5 nodes from 1 to 5, I need to build the
> shortest path tree from node 1 to nodes 2,3,5. So my question is
> instead of keeping separate lists for each destination node's shortest
> path. How can I represent and store them in a tree structure using
> python. Then I can easily find out what are the common nodes in the
> path to each destination.

A tree is just a connected acyclic rooted graph, so however you're
representing graphs should be a perfectly natural representation for
your shortest paths tree. In effect, you just treat the shortest
paths operation as an subgraph operation which only preserves the
edges that are part of a shortest path.

Geremy Condra




More information about the Python-list mailing list