Suppose that CONNECTED-COMPONENTS is run on the undirected graph G = (V, E), where V = {a, b, c, d, e, f, g, h, i, j, k} and the edges of E are processed in the following order: (d, i), (f, k), (g, i), (b, g), (a, h), (i, j), (d, k), (b, j), (d, f), (g, j), (a, e), (i, d). List the vertices in each connected component after each iteration of lines 3-5.
{a} {b} {c} {d} {e} {f} {g} {h} {i} {j} {k}
- (d,i) => {a} {b} {c} {d i} {e} {f} {g} {h} {j} {k}
- (f,k) => {a} {b} {c} {d i} {e} {f k} {g} {h} {j}
- (g,i) => {a} {b} {c} {d g i} {e} {f k} {h} {j}
- (b,g) => {a} {b d g i} {c} {e} {f k} {h} {j}
- (a,h) => {a h} {b d g i} {c} {e} {f k} {j}
- (i,j) => {a h} {b d g i j} {c} {e} {f k}
- (d,k) => {a h} {b d g i j f k} {c} {e}
- (b,j) => {a h} {b d g i j f k} {c} {e}
- (d,f) => {a h} {b d g i j f k} {c} {e}
- (g,j) => {a h} {b d g i j f k} {c} {e}
- (a,e) => {a e h} {b d g i j f k} {c}
Show that after all edges are processed by CONNECTED-COMPONENTS, two vertices are in the same connected component if and only if they are in the same set.
If two vertices are not in the same set, meaning that no edge connecting the set of one vertice with the other. So two vertices are in the same connected component if and only if they are in the same set.
During the execution of CONNECTED-COMPONENTS on an undirected graph G = (V, E) with k connected components, how many times is FIND-SET called? How many times is UNION called? Express your answers in terms of |V|, |E|, and k.
- FIND-SET : 2|E|
- UNION : |V| - k
Follow @louis1992 on github to help finish this task.