[英]Worst-Case Graph for Prim's Algorithm
My Algorithms class is talking about Prim's Algorithm as a method of finding Minimum Spanning Trees of weighted graphs. 我的算法课谈论的是Prim算法,它是一种找到加权图的最小生成树的方法。 Our professor asked us to try to think of an example of a graph that Prim's Algorithm takes N^2 time to solve (N = number of Vertices).
我们的教授要求我们尝试考虑一个图的示例,该图的基本算法需要N ^ 2的时间来解决(N =顶点数)。 No one in the class could think of one off the top of their head, so I'm asking you.
班上没人能想到一个人,所以我问你。 I'm pretty sure Prim's Algorithm = O(N^2), so this would be the worst-case scenario for the algorithm.
我很确定Prim的算法= O(N ^ 2),所以这将是该算法最坏的情况。
What's a good example of a graph that takes N^2 time for Prim's Algorithm to solve? 有什么很好的示例图需要花费N ^ 2的时间来求解Prim的算法?
If I understand your question correctly, the example is trivial. 如果我正确理解了您的问题,那么这个例子很简单。
If the graph is complete, there're O(N^2)
edges, so just reading the graph is O(N^2)
. 如果图是完整的,则有
O(N^2)
边,因此仅读取图就是O(N^2)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.