The self-link-is-null-link solution only works when the structure is
acyclic (or more specifically when nodes cannot validly link to
themselves). You only need to have null links when there's a fixed number
of link "slots" – if the number of links is a variable-sized array, you can
just use an empty array for the "no links" case. However, I've found that
on modern machines I've found that keeping the data in one place and the
link structure in another place is a *huge* win. For example, to represent
a k-ary tree of strings, you could do this:

data = Array(UTF8String, n)
links = Array(Int, n, k)


where links[i,j] represents the index of the jth child of the ith node and
0 indicates no child. If the tree has variable arrity, then that's a
different issue, but a sparse matrix representation is likely to be a good
choice.

Reply via email to