Mô phỏng thuật toán Hợp-Tìm (Union-Find / DSU)

Disjoint Set Union · Nhóm: Cấu trúc dữ liệu

Hợp-Tìm (Union-Find / DSU) (Disjoint Set Union), nhóm Cấu trúc dữ liệu.

Mã Python

def find(x):
    while parent[x] != x:
        x = parent[x]
    return x

def union(a, b):
    ra, rb = find(a), find(b)
    if ra == rb:
        return
    parent[ra] = rb

Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.