Skip to content

Bug with union in disjoint_set #4764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yunhenk opened this issue Sep 15, 2021 · 0 comments
Closed

Bug with union in disjoint_set #4764

yunhenk opened this issue Sep 15, 2021 · 0 comments

Comments

@yunhenk
Copy link

yunhenk commented Sep 15, 2021

https://github.com/TheAlgorithms/Python/blob/master/data_structures/disjoint_set/disjoint_set.py

def union_set(x, y):
    """
    union two sets.
    set with bigger rank should be parent, so that the
    disjoint set tree will be more flat.
    """
    x, y = find_set(x), find_set(y)
    if x.rank > y.rank:
        y.parent = x
    else:
        x.parent = y
        if x.rank == y.rank:
            y.rank += 1

here need check if x==y

@poyea poyea changed the title bug with disjoint_set Bug with union in disjoint_set Sep 15, 2021
joesinghh added a commit to joesinghh/Python that referenced this issue Sep 24, 2021
@joesinghh joesinghh mentioned this issue Sep 24, 2021
14 tasks
joesinghh added a commit to joesinghh/Python that referenced this issue Sep 24, 2021
shermanhui pushed a commit to shermanhui/Python that referenced this issue Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants