简体   繁体   中英

Find path between two nodes in a tree (a simple connected tree not of any specific type)

我想找到一棵树的两个节点之间的路径。我在网络上发现的大多数方法都与图有关,并且可能在图的情况下比树更复杂( https://www.geeksforgeeks.org/find- path-given-source-destination /)https://www.geeksforgeeks.org/print-paths-given-source-destination-using-bfs/

You will need to search in the tree. Since we do not have any additional innformation, we do not have any clues where to look at, so it will either be a depth-first search , or breadth-first search . When your nodes are found, you will know the path, so you can stop the search. If you need further optimization, then you will need to find some additional pattern in your data-source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM