I need tree traversal algorithms for arbitrary trees in both first and first traversal order. The tricky part is that I need to start with an arbitrary node and continue until another specific node is passed.
Now I can use any of the usual algorithms and ignore the nodes passed until Iām at the beginning of the node and continue to the end of the node (which I am doing now), but this is ugly and inefficient.
Any suggestions please.
UPDATE: each of my nodes has an identifier associated with them. In some cases, I have the beginning and end of node links to start with. In other cases, they give me two identifiers, I check if a given node is the beginning of a node or the end of a node by checking their identifiers. I use depth traversal to find the beginning of a node. Both the start and end nodes can be anywhere in the hierarchy. I hope that someone can come up with an idea for the case when I have already been given links to the initial - node and end - node. BTW, the nodes in the tree are actually sorted according to the sort order, which starts at 0 for each of the sub-nodes of the node and there is one root node
source share