According to Wikipedia, an important choice when making a suffix tree implementation is the parent-child relationships between nodes. The most common one is using linked lists called sibling lists.
How does this work in Java?
In a sibling list, each node has exactly two references: first-child
and next-sibling
. This lets you iterate over all the children of a node by starting with first-child
, and then following next-sibling
until you get to the child whose next-sibling
is null
. I don't see why Java would be any different from any other programming language.
It's interesting to note that this representation is virtually identical to the standard representation of a binary tree, where left
is spelled first-child
and right
is spelled next-sibling
. This demonstrates the 1-1
relationship between binary trees and general trees with the same number of nodes. (It might seem contradictory at first, but note that a binary tree may have only a left
child, or only a right
child, and those are considered different. By contrast, in a general tree, there is only one way for a node to have one child.
Parent has a list of child nodes (either as array, double linked list or so) Each child has a link to its parent. Traversing is extremely simple as you don't need a stack.