![]() ![]() ![]() Place matches in a third list, sorted by hops from B + hops from E. B's list is sorted by hops from B while E's list is sorted by hops from E.įor each element in B's list, attempt to find it in E's list. Let both B and E have copies of the list of graph nodes. Every node in your graph will have two variables associated with it: hops from B and hops from E. If you can only go "up" the tree, then I suggest you perform a BFS from E and also a BFS from B. Now that you've clarified a few things, I think I understand what you're looking for. For the nodes that can reach both E and B, you can find the node that minimizes PathLengthToE + PathLengthToB. If you're not worried about complexity, then you could compute an A* (or Dijkstra's shortest path) from every node to both E and B. Perhaps you mean the ancestor on the tree output of a DFS or BFS? Or perhaps by 'ancestor' you mean the node in the digraph that minimizes the number of hops from E and B? If the graph has cycles then 'ancestor' is loosely defined.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |