Graph theory algorithm to find vertex with out-degree 0 and in-degree (n-1)

六月ゝ 毕业季﹏ 提交于 2019-12-11 11:29:42

问题


I'm wondering how to determine whether a directed graph has a get-stuck vertex, which is defined as a vertex with in-degree n-1 and out-degree 0.

I guess the dumb way would be to print the in-degree and out-degree of every vertex in the graph, but that's O(m+n). I'm interested in an O(n) algorithm. Any ideas?

Thanks!!


回答1:


(I assume that n is vertices and m is edges.)

Note that there is at most one get-stuck vertex in a graph.

Suppose we have an O(n) algorithm. If m is large, we must reach a conclusion without considering every edge.

If we conclude that the get-stuck vertex exists, we are asserting that no unconsidered edge leads out of it, which we can't know.

Therefore I don't think that O(n) is possible.

O(m) is pretty straightforward.




回答2:


I agree with Beta, there is no way you can solve this problem by o(n), because you have to visit each edge at least once to verify that it is a get-stuck node.



来源:https://stackoverflow.com/questions/22752583/graph-theory-algorithm-to-find-vertex-with-out-degree-0-and-in-degree-n-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!