Summary of Union-find algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.