检查两个顶点是否相连
可能的重复:
如何在图表中搜索路径?
我想知道在“图表”中最好的方法是什么,其中的对象确实引用了它们的邻居,但我也有一个概述(带有坐标上的对象的哈希图),以确定其中两个对象是否连接。
我读到 Dijkstra 可能对此效率低下,并且我阅读了有关 BFS 和 DFS 的内容。
据我了解,BFS 可能会接近我的需要,我可以做得更好吗?有更常见的方法来解决这个问题吗?也许更容易?时间复杂度确实发挥了作用:)
Possible Duplicate:
How can I search a graph for a path?
I was wondering what the best approach was in a 'graph' with objects that do refer to their neighbours, but of whom i also have an overview (a hashmap with objects on coordinates), to determine wether two of these objects are connected.
I read Dijkstra might be unefficient for this and i read up about BFS and DFS.
From my understanding BFS might get close to what i need, can i do better? Is there a more common way of solving this? Maybe even easier? Time complexity does play a role :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查java中的这段代码,当你得到邻接矩阵时,你会看到节点是否连接:
check this code in java, and when you get the adjacency matrix you see if nodes are connected: