找到树的父节点以创建尽可能短的树高
我有一个无向图,表示为欧几里德权重的邻接矩阵。我用它来表示更大完整图的最小生成树。
我想要找到的是图中的单个节点,当用作根节点时,会创建尽可能短的树高度。我想出的是使用每个节点作为根执行深度优先遍历,并跟踪所看到的最短高度。有没有更快的方法来完成这个任务?
I have an undirected graph represented as an adjacency matrix of Euclidean weights. I'm using this to represent the minimum spanning tree for a larger complete graph.
What I want to find is the single node within the graph that, when used as the root node, creates the shortest possible tree height. What I've come up with is performing a depth-first traversal using every node as the root, and keeping track of the shortest height seen. Is there a faster way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一道经典的算法题。您要寻找的东西称为树的中心,可以使用简单的迭代算法找到它。 这个问题有一个很好的答案,解释了如何做到这一点。
希望这有帮助!
This is a classic algorithms question. What you're looking for is called the center of the tree, and it can be found using a simple iterative algorithm. This question has a great answer that explains how to do it.
Hope this helps!