How to determine if two nodes are connected?

前端 未结 11 1180
清酒与你
清酒与你 2020-12-09 03:31

I\'m concerned that this might be working on an NP-Complete problem. I\'m hoping someone can give me an answer as to whether it is or not. And I\'m looking for more of an an

11条回答
  •  无人及你
    2020-12-09 04:26

    Dijkstra's is overkill!! Just use breadth first search from A to search for the node you want to reach. If you can't find it, it's not connected. Complexity is O(nm) for each search, which is less then Dijkstra.

    Somewhat related is the max-flow/min-cut problem. Look it up, it might be relevant to your problem.

提交回复
热议问题