Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Boruvka MST算法在森林中搜索边缘的最佳方法是什么?_Java_Algorithm_Data Structures_Graph_Minimum Spanning Tree - Fatal编程技术网

Java 使用Boruvka MST算法在森林中搜索边缘的最佳方法是什么?

Java 使用Boruvka MST算法在森林中搜索边缘的最佳方法是什么?,java,algorithm,data-structures,graph,minimum-spanning-tree,Java,Algorithm,Data Structures,Graph,Minimum Spanning Tree,我目前正在编写巴鲁夫卡算法,如下所示。但是我有一个问题要检查边e=uv,如果它已经存在于使用贪婪选择已经获取的边列表中。如何在O(logn)时间内搜索边e?你能帮个忙吗。。。搜索操作可以使用BFS或DFS完成,并检查边缘是否存在,但如果我在每个阶段都这样做,那么这将成为一个代价高昂的操作 Boruvka { while (T < n-1 edges) { Find the components of T for each tree Ti of the forest T { F

我目前正在编写巴鲁夫卡算法,如下所示。但是我有一个问题要检查边e=uv,如果它已经存在于使用贪婪选择已经获取的边列表中。如何在O(logn)时间内搜索边e?你能帮个忙吗。。。搜索操作可以使用BFS或DFS完成,并检查边缘是否存在,但如果我在每个阶段都这样做,那么这将成为一个代价高昂的操作

Boruvka
 { 
while (T < n-1 edges)
 { 
Find the components of T 
for each tree Ti of the forest T
 { 
Find the smallest weight edge e = uv such that u is in Ti and v is not in Ti 

//Before adding e to T I have to check if it already exists in the list of greedy edges or not. If it exists then I would like to skip adding e to T and go to the next phase. 
Add e to T 
 } 
} 
 return T 
}
Boruvka
{ 
而(T

但存在一个问题,即多次添加一条边。所以为了消除这一点,我们需要在添加它之前检查边是否已经添加到T。此检查是否有O(n)实现?

您应该为每个组件使用不相交的集合数据结构或其他一些数据结构。当一条边连接两个不同的连接组件时,该边以前如何存在于树边列表中?请阅读

无论何时选择一条边,都应该合并由该边连接的两个组件。合并时,把这个大的分量看作一个新的顶点,它的边应该是它的组成部分的外边缘。< /P>