I studied the union find algo and found it is very useful in following ways.
to find out if 2 node are connected or not
to compress the path. (save space)
if the problem is to find if 2 node connected or not , then we can use union
find.But if we have to find out the path between these 2 node,
then how can we use the data structure which is use to find
union find ( data structure use is - it store root element in
arrays of node. form kind of tree)?
I tried a lot and found that we have to use graph to find out the path\
between node and can not use union find data structure .
any other views on it.
答案 0 :(得分:0)
有许多算法可以实现联合/查找,但是从您的问题来看,您似乎指的是不相交的集合林实现。因此,我将重点关注这一特定实施。
为了提高联合和查找操作的性能,不相交集森林应用不同的启发式方法,例如:路径压缩。这些启发式算法可以提高渐近复杂度的联合和找到,但结果却无法重建原始的图形结构。因此,您将无法在两个顶点之间找到路径。毕竟算法是为了解决这个特殊问题 - 能够执行联合和查找。
但是,您可以使用其他一些联合/查找实现。例如,您可以使用与Disjoint set forest相同的想法,但没有路径压缩(您仍然可以按等级使用union)。这当然会增加并集和查找的渐近复杂度,但也会保留图结构,因此您将能够找到顶点之间的路径。