Not familiar with the Union find algorithm, you can see
http://blog.csdn.net/dm_vincent/article/details/7655764
http://blog.csdn.net/dm_vincent/article/details/7769159
Personally, the blog is very easy to understand, the second link is a few examples of the use of bloggers.
A few questions to consider:
What scenario does this algorithm typically apply to? How to use it?
How do I get the problem to union-find or what is the purpose of the Union?
How to union, that is, two elements to meet what conditions can be union?
>> two meta-related
< P dir= "ltr" style= "LINE-HEIGHT:1.2;MARGIN-TOP:0PT;MARGIN-BOTTOM:0PT;" > |
< P dir= "ltr" style= "LINE-HEIGHT:1.2;MARGIN-TOP:0PT;MARGIN-BOTTOM:0PT;" > |
|
Graph Valid Tree |
Two vertices of an edge |
|
< P dir= "ltr" style= "LINE-HEIGHT:1.2;MARGIN-TOP:0PT;MARGIN-BOTTOM:0PT;" > |
|
UNION ALL nodes with the specified ID node as the root, summing the value of the elements in the Union |
< P dir= "ltr" style= "LINE-HEIGHT:1.2;MARGIN-TOP:0PT;MARGIN-BOTTOM:0PT;" > |
Two adjacent 1 elements |
union after the union count (by counting the number of root nodes in the Union array) |
Surrounded regions |
All o elements from the boundary are union together |
When the union is finished, those that do not have an O in the bounding box are required to be flipped. |
The purpose of union, Graph
Graph Valid Tree
subtree Sum
Number of Islands
https://leetcode.com/problems/surrounded-regions/
This problem debug for a long time, a 20*20 case always pass, because the Oroot rank value is not set large enough,
will be replaced by other elements in the matrix thereby oroot is no longer oroot cause the entire matrix o will be all changed to X.
surrounded Region
Summary of Union-find algorithm