# Algorithms_in_C++: graph/connected_components.cpp File Reference

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

{
/// creating a graph with 4 vertex
graph g(4);
/// Adding edges between vertices
g.addEdge(1, 2);
g.addEdge(3, 2);
/// printing the connected components
std::cout << g.getConnectedComponents();
return 0;
}
Here is the call graph for this function:
graph
Definition: bfs.cpp:3
std::cout