Graph::isBipartite

Function


bool isBipartite();

Returns whether this graph is a bipartite graph or not.

Parameters

None

Return value

Return true if the graph is a bipartite graph, false otherwise.

Example

#include "HKUAL_graph.h"
#include <iostream>
using namespace std;
using namespace HKUAL;

int main(){
    Graph<string> g;
    g.addVertex("A");
    g.addVertex("B");
    g.addVertex("C");
    g.addVertex("D");
    g.addVertex("E");
    g.addVertex("F");
    g.addEdge("A","D");
    g.addEdge("A","E");
    g.addEdge("A","F");
    g.addEdge("B","D");
    g.addEdge("B","E");
    g.addEdge("B","F");
    g.addEdge("C","D");
    g.addEdge("C","E");
    g.addEdge("C","F");

    if (g.isBipartite())
        cout <<"Yes" << endl;
    else
        cout <<"No" << endl;
    return 0;
}          

Output

Yes

Time Complexity

, for is number of edges and is total number of vertives.

© The University of Hong Kong Algorithms Library - hkual@cs.hku.hk