Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
connected_components.cpp File Reference

Graph Connected Components (Connected Components) More...

#include <algorithm>
#include <iostream>
#include <vector>
Include dependency graph for connected_components.cpp:

Classes

class  graph
 

Functions

int main ()
 

Detailed Description

Graph Connected Components (Connected Components)

Author
Ayaan Khan

A graph is a collection of nodes also called vertices and these vertices are connected by edges. A connected component in a graph refers to a set of vertices which are reachable form one another.

Example - Here is graph with 3 connected components
     3   9           6               8
    / \ /           / \             / \
   2---4           2   7           3   7
   first          second           third
   component      component        component

Function Documentation

◆ main()

int main ( )

Main function

creating a graph with 4 vertex

Adding edges between vertices

printing the connected components

111  {
112  /// creating a graph with 4 vertex
113  graph g(4);
114 
115  /// Adding edges between vertices
116  g.addEdge(1, 2);
117  g.addEdge(3, 2);
118 
119  /// printing the connected components
120  std::cout << g.getConnectedComponents();
121  return 0;
122 }
Here is the call graph for this function:
graph
Definition: bfs.cpp:3
std::cout