A possibly dumb question: Given a labeled or unlabeled tree
(in the sense of graphs), how could one best use C to describe it?
(I don't exactly know but have the impression that this might be
rather simple in Lisp.)
Thanks.
M. K. Shen
This is a brilliant question. Even in lisp there are many ways to do
it. Which you choose depends on design goals and requirements. Some
questions to consider:
0. Does the tree have special structure (like a search tree, priority
queue, or prefix tree)?
1. How important is space efficiency? (Is the tree large compared to
available memory?)
2. How many children per node?
3. Are children to be dynamically or statically identified/named?
4. If the number of children varies, how widely?
5. Is constant time access to parents required? Siblings?
6. Are the data represented exogenously with respect to the tree?
(I.e. is it already stored in another tree, so you only need to point
to it?) Or will they be endogenous?
7. Are tree nodes to be exogenous for some other data structure
(pointed to by it)?
8. Does the tree need to be persistent?
9. Is a human-readable representation required?
10. Do tree operations need to be atomic (in a multi-threading
environment)?
11. Do tree operations need to be transactions (in the database sense
of commit/rollbacck)?
12. Is it better to pre-allocate all tree storage or allocate on the
fly? Is the max number of nodes limited?
13. If the tree is ordered, do you need data ordinals?
14. If the tree is for data access, does it need to be self-height-
limiting or -balancing?
15. Do tree operations need to be undoable?
All these and others affect the "best" C representation. If you don't
have many such criteria, then that's a criterion in itself. It
alllows you can trade between simplicity and flexibility for future
new requirements.
If you narrow the question a bit, we can get to the details.