Click to See Complete Forum and Search --> : recursive algorithm for shortest path in binary trees


v_swethu
June 2nd, 2006, 08:51 PM
Suppose we are given a binary tree T of 'n' nodes and a pointer to some node p. How do we compute the shortest path(number of edges) from node 'p' to all other nodes of the binary tree. We could use an array to store the distances.

We are also given another array D[1:n] which stores the depth of each node from the root. Depth of root = 0, depth of the next level of nodes =1 and so on.


Note: the code should be recursive.


I have been thinking over this for a long time. Does anyone know how to approach this.

-sweta Venkatesh