[英]Big O complexity of finding cycles in an Undirected graph
I need to find the complexity of finding all the cycles in a undirected graph consisting of 50 nodes. 我需要找到在包含50个节点的无向图中找到所有循环的复杂性。 Moreover, if the graph grows large, will the complexity be changed and what will be it if the network grows considerably large.
此外,如果图形变大,那么复杂度是否会发生变化,如果网络变得相当大,则复杂度将如何变化。 In addition, if I find only few cycles then how do I find the complexity of finding few cycles in a graph.
另外,如果我只找到几个循环,那么如何找到在图中找到几个循环的复杂性。
Thanking you in Anticipation! 感谢你在期待!
Using depth-first search and proactive marking of nodes, you can find cycles simply by noticing any time that you run into a marked node in your search. 使用深度优先搜索和主动标记节点,只需注意在搜索中遇到标记节点的任何时间,就可以找到周期。
This is an O(V+E)
approach, I believe, where V
is the number of vertices or nodes and E
is the number of edges or connections. 我相信这是一种
O(V+E)
方法,其中V
是顶点或节点的数量, E
是边或连接的数量。
If you put the nodes in a particular branch on a stack, you can also easily determine the cycle path. 如果将节点放在堆栈上的特定分支中,则还可以轻松确定循环路径。 Just make sure to pop a node out each time you backtrack.
只要确保每次回溯时弹出一个节点即可。
A given graph can have exponential number of cycles (in the size of graph). 给定的图可以具有指数周期(以图的大小为单位)。 Consider a bipartite graph where v i is connected to w i+1 % n and w i is connected to v i+1%n .
考虑一个二部图,其中v i连接到w i + 1%n,并且w i连接到v i + 1%n 。
So unless you have specific kind of graphs, there is no hope for polynomial time solutions. 因此,除非您拥有特定种类的图,否则多项式时间解是没有希望的。 A solution that runs in exponential time is very easy to build.
以指数时间运行的解决方案非常易于构建。 Consider all permutations of vertices, see if that ordering results in a cycle.
考虑所有顶点的排列,看看该顺序是否导致一个循环。
Of course, in practical terms you can come up with solutions that are much faster than that. 当然,实际上,您可以想出比这快得多的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.