TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Class for representing graph as an adjacency list. More...
Public Member Functions | |
Graph (int size) | |
Constructor that initializes the graph on creation. | |
void | addEdge (int u, int v) |
Function that add an edge between two nodes or vertices of graph. | |
bool | is_bipartite () |
function to add edges to our graph | |
Private Attributes | |
int | n |
size of the graph | |
std::vector< std::vector< int > > | adj |
adj stores the graph as an adjacency list | |
std::vector< int > | side |
stores the side of the vertex | |
Class for representing graph as an adjacency list.
Definition at line 51 of file is_graph_bipartite.cpp.
|
inlineexplicit |
Constructor that initializes the graph on creation.
size | number of vertices of the graph |
Definition at line 65 of file is_graph_bipartite.cpp.
void graph::is_graph_bipartite::Graph::addEdge | ( | int | u, |
int | v ) |
Function that add an edge between two nodes or vertices of graph.
u | is a node or vertex of graph |
v | is a node or vertex of graph |
Definition at line 83 of file is_graph_bipartite.cpp.
bool graph::is_graph_bipartite::Graph::is_bipartite | ( | ) |
function to add edges to our graph
function that checks whether the graph is bipartite or not the function returns true if the graph is a bipartite graph the function returns false if the graph is not a bipartite graph
Here, side refers to the two disjoint subsets of the bipartite graph. Initially, the values of side are set to -1 which is an unassigned state. A for loop is run for every vertex of the graph. If the current edge has no side assigned to it, then a Breadth First Search operation is performed. If two neighbours have the same side then the graph will not be bipartite and the value of check becomes false. If and only if each pair of neighbours have different sides, the value of check will be true and hence the graph bipartite.
true
if th graph is bipartite false
otherwise Definition at line 106 of file is_graph_bipartite.cpp.
|
private |
adj stores the graph as an adjacency list
Definition at line 56 of file is_graph_bipartite.cpp.
|
private |
size of the graph
Definition at line 53 of file is_graph_bipartite.cpp.
|
private |
stores the side of the vertex
Definition at line 58 of file is_graph_bipartite.cpp.