Connected components in undirected graph

Algorithm

ConnectedComponent(){
1. initialized all vertices as unchecked
2. for all vertices
    - if not checked than apply dfs by calling dfs(v,checked[]) function .
}

dfs(v,checked[]){
1. mark v as checked and diaplay it
2. for neighbouring vertex 
   - if not checked apply dfs to unchecked neighbouring vertex
}

Properties

Advantages

Adjacency Matrix

adjacency matrix is a matrix that maintain the information of adjacent vertices .

Algorithm

  1. Initialized a 2D array Adj[][] globally .
  2. For each edge in adj[][], Update value at Adj[X][Y] to 1 and
  3. Display the Adjacency Matrix after the above operation for all the pairs in adj[][].

Properties