Graphs: find a sink in less than O(|V|) - or show it can't be done

前端 未结 7 1134
死守一世寂寞
死守一世寂寞 2021-02-01 10:17

I have a graph with n nodes as an adjacency matrix.

Is it possible to detect a sink in less than O(n) time?

If yes, how? If no

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 10:34

    In the case of a general directed graph, no, and I don't think it needs a formal proof. At best, detecting a sink requires you to either identify the node and check that it has no outgoing edges, or inspect every other node and see that none of them have connections coming from it. In practice, you combine the two in an elimination algorithm, but there is no shortcut.

    By the way, there is disagreement over the definition of sink. It's not usual to require all other nodes connect to the sink, because you can have multiple sinks. For instance, the bottom row in this diagram are all sinks, and the top row are all sources. However, it allows you to reduce the complexity to O(n). See here for some slightly garbled discussion.

提交回复
热议问题