mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Performed the requested changes
This commit is contained in:
parent
d87a6685f6
commit
ab26183183
@ -1,8 +1,7 @@
|
||||
/**
|
||||
* @file is_graph_bipartite
|
||||
*
|
||||
* @brief Algorithm to check whether a graph is bipartite
|
||||
* (https://en.wikipedia.org/wiki/Bipartite_graph)
|
||||
* @brief Algorithm to check whether a graph is [bipartite](https://en.wikipedia.org/wiki/Bipartite_graph)
|
||||
*
|
||||
* @details
|
||||
* A graph is a collection of nodes also called vertices and these vertices
|
||||
@ -25,7 +24,6 @@
|
||||
* \ /
|
||||
* 3
|
||||
*
|
||||
*
|
||||
* @author [Akshat Vaya](https://github.com/AkVaya)
|
||||
*
|
||||
*/
|
||||
@ -74,10 +72,16 @@ void graph::addEdge(int u, int v) {
|
||||
* @brief 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
|
||||
*
|
||||
* @details
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
bool graph::is_bipartite(){
|
||||
n = adj.size();
|
||||
side.resize(n,-1);
|
||||
bool check = true;
|
||||
std::queue<int> q;
|
||||
for (int current_edge = 0; current_edge < n; ++current_edge)
|
||||
|
Loading…
Reference in New Issue
Block a user