Suppose I am given a undirected tree and I need to find a path(the only path) between two nodes.
What is the best algorithm to do it.I probably could use a Dijkstra’s algorithm but there a probably something better for trees.
C++ example would be helpful but not necessary
Thank you
Supposing you have
then what could be done is traversing the whole tree starting at root keeping the whole chain during the traversal. If you find e.g. node1 then you save the current chain, if you find node2 then you check for the intersection… in code (UNTESTED):