Union-Find or DFS: which one is better to find connected component?
The union-find algorithm is best suited for situations where the equivalence relationship is changing, i.e., there are “Union” operations which need to be performed on your set of partitions. Given a fixed undirected graph, you don’t have the equivalence relationships changing at all – the edges are all fixed. OTOH, if you have a graph … Read more