News for hackers. Stuff that matters.
Re:Ask HN: What are some cool but obscure data structures yo... by clashmeifyoucan on Friday July 22, 2022 @08:27PM (#32198855)
a textbook example of an algorithm that works very well with union-find is the kruskal's algorithm to find the minimum weight spanning tree given a graph. Using union-find improves the time complexity of the algorithm from O(V²) to O(ElogV).

This happens because kruskal's algorithm essentially selects the cheapest edge not already included in our spanning tree that won't cause a cycle. So union-find is able to speed up this potential cycle check which would otherwise be naively quadratic.

There are no comments on this comment yet.