[Tutor] Most efficient representation of a tree?
VanL
vlindberg@verio.net
Fri, 04 May 2001 18:11:09 -0600
Hello,
What would be the most efficient representation of a tree?
In this tree, each node could have an arbitrary number of children.
I also wanted to be able to order the children so I can traverse the
trees in different ways (preorder, postorder, etc). Anyway, at least a
leftmost-child, right-sibling ordering.
I was considering two options:
1. A modification of Guido's adjacency-list implementation of a graph
(see http://www.python.org/doc/essays/graphs.html). After all, this
sort of tree is just special case sparse graph.
2. A node class with a parent link and a list of links to each child --
essentially a generalization of the linked list class that I posted here
a month ago.
Any other options?
Does anyone have any idea how these would compare in terms of speed and
execution resources?
Thanks,
VanL