http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) writes:

> Peter Mueller <(E-Mail Removed)> writes:

>>I have a non binary tree and looking for a solution to find the path

>>between two given ¯¯¯¯¯¯¯¯

>

> Sometimes, there are /several/ paths between two points.
Not in a tree. Unless you allow going back and forth along the

same edge as part of a path (i.e., visiting the same node

twice), there is exactly one path between any two node.

> However, there will not be any path if the tree is empty.
Nor will there be any nodes, and since the question was on how

to find a path between two nodes, we know the tree isn't empty.

Apart from that, the solution is fine. Trace a path from each node

to the root. Then find the lowest node that is on both paths and

make a path from one node to that node, and from there to the other node.

If your tree keeps information about the depth of each node in the node,

then you won't have to trace the paths all the way to the root, but can

compare nodes at the same lavel until the paths meet.

/L

--

Lasse Reichstein Nielsen -

http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>

'Faith without judgement merely degrades the spirit divine.'