Skip to content

Bug with union in disjoint_set #4764

Closed
Closed
@yunhenk

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

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