Bug with union in disjoint_set · Issue #4764 · TheAlgorithms/Python · GitHub
Skip to content

Bug with union in disjoint_set #4764

Description

@yunhenk

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions