Current position:  Home > Default > How to find a shortest distance in a tree from one node to another node

How to find a shortest distance in a tree from one node to another node

Time:November 30
Advertisement
Hi
my question is same as above.. there are many algorithms which i had come across but they are mainly for graphs or weighted trees. i want to traverse through a binary tree... how is it possible.. any link to the solution or source code sample will work...
Thanks
Advertisement
Rastogha wrote:
redfalconf35 wrote:
[http://en.wikipedia.org/wiki/Tree_traversal|http://en.wikipedia.org/wiki/Tree_traversal]
that is good link. but . given a node is it possible for me to find all is ancestors or parents so that i can traverse up the hierarchy.....Most simple tree implementations just have references from each node to its children. You either want:
1. the tree data structure to maintain back pointers -- from each child back to its parent, OR
2. a bread crumb trail: as you traverse the tree or otherwise pick a node, you need to have built a list of references from the root down to the node in question.