# Calcolo delle componenti connesse A B A C D F E BCDEF X = {[A,B], [C,F], [E,D], [A,D], [B,E], [A,E]} For v = 1 to n do MakeSet(v) p = [1 2 3 4 5 6] rank.

## Presentation on theme: "Calcolo delle componenti connesse A B A C D F E BCDEF X = {[A,B], [C,F], [E,D], [A,D], [B,E], [A,E]} For v = 1 to n do MakeSet(v) p = [1 2 3 4 5 6] rank."— Presentation transcript:

Calcolo delle componenti connesse A B A C D F E BCDEF X = {[A,B], [C,F], [E,D], [A,D], [B,E], [A,E]} For v = 1 to n do MakeSet(v) p = [1 2 3 4 5 6] rank = [0 0 0 0 0 0]

Calcolo delle componenti connesse ABCDEF For each [u,v] E do r = FindSet(u) s = FindSet(v) If r s then Union(r,s) [A,B] r = FindSet(A) = A s = FindSet(B) = B Union(r,s) If rank[r] < rank[s] then p[r] = s else p[s] = r If rank[r] = rank[s] rank[r]++ p = [1 1 3 4 5 6] rank = [1 0 0 0 0 0] B A C D F E

Calcolo delle componenti connesse ABCDEF [C,F] r = FindSet(C) = C s = FindSet(F) = F p = [1 1 3 4 5 3] rank = [1 0 1 0 0 0] B A C D F E For each [u,v] E do r = FindSet(u) s = FindSet(v) If r s then Union(r,s) Union(r,s) If rank[r] < rank[s] then p[r] = s else p[s] = r If rank[r] = rank[s] rank[r]++

Calcolo delle componenti connesse ABCDEF [E,D] r = FindSet(E) = E s = FindSet(D) = D p = [1 1 3 4 4 3] rank = [1 0 1 1 0 0] B A C D F E For each [u,v] E do r = FindSet(u) s = FindSet(v) If r s then Union(r,s) Union(r,s) If rank[r] < rank[s] then p[r] = s else p[s] = r If rank[r] = rank[s] rank[r]++

Calcolo delle componenti connesse ABCDEF [A,D] r = FindSet(A) = A s = FindSet(D) = D p = [1 1 3 1 4 3] rank = [2 0 1 1 0 0] B A C D F E For each [u,v] E do r = FindSet(u) s = FindSet(v) If r s then Union(r,s) Union(r,s) If rank[r] < rank[s] then p[r] = s else p[s] = r If rank[r] = rank[s] rank[r]++

Calcolo delle componenti connesse ABCDEF [B,E] r = FindSet(B) = A s = FindSet(E) = A p = [1 1 3 1 4 3] rank = [2 0 1 1 0 0] B A C D F E For each [u,v] E do r = FindSet(u) s = FindSet(v) If r s then Union(r,s) Union(r,s) If rank[r] < rank[s] then p[r] = s else p[s] = r If rank[r] = rank[s] rank[r]++

Calcolo delle componenti connesse ABCDEF [A,E] r = FindSet(A) = A s = FindSet(E) = A p = [1 1 3 1 4 3] rank = [2 0 1 1 0 0] B A C D F E For each [u,v] E do r = FindSet(u) s = FindSet(v) If r s then Union(r,s) Union(r,s) If rank[r] < rank[s] then p[r] = s else p[s] = r If rank[r] = rank[s] rank[r]++

Similar presentations