can anyone please tell me which theorem is to be applied in connecting islands?? asked 05 Feb '15, 23:29

The question is basically asking if two vertices belong to the same connected component( edges are added dynamically here though). UnionFind Disjoint data structure can be used to solve this problem. For each edge to be added between x any y, take the Union of set(x) and set(y) . For checking if vertices x and y are connected or not, see if they both belong to the same set. answered 05 Feb '15, 23:50
