각 객체의 이름을 숫자로 붙인다
(When programming, it’s convenient to name objects to )
A와 B가 ‘연결 되어 있다’라는 말은 동치 관계(equivalence relation)임을 가정한다.
연결된 요소(Connected components)는 상호 연결된 객체들의 최대 집합(maximal set)이다.
두 객체가 동일한 연결된 요소에 있는지를 확인
(to check if two objects are in the same component)
두 객체를 포함하는 연결 요소의 합집합으로 연결 요소를 대체함
(to replace components containing two objects with their union)
union(2,5)
를 통해 연결된 요소가 하나 줄어듦
public class UF // UF for union find
UF (int N) // union-find 자료구조를 N개의 객체(0 to N - 1)로 초기화
void union(int p, int q) // p와 q 사이에 연결 추가
boolean connected(intp, int q) // p와 q가 같은 요소인가? -> boolean 자료형으로 반환
int find(int p) // p(0 to N - 1)에 대한 연결 식별자
int count() // 전체 요소의 개수를 반환