A linear-time algorithm to determine an odd-length cycle in a directed graph with the assumption that the graph is strongly connected this is done by BFS. or also finding out whether a directed graph is bipartite or not.
Algorithm to determine the given graph isbipartite or not in a directed graph by breadth first search (BFS) is as follows,
1). Consider graph which contain two sets of graphs named asand.
2). Take Red color node as a source vertex and put this vertex in a set. after that color all the vertices blue which are directly connected to the source vertex and put these vertices to another set named.
3). After that the blue vertex is connected with other node, color it red and put into the set ofgraph.
4). The vertices of blue color and the vertices are in red color are not directly connected to each other. It means take all vertices of graphis in red color and all vertices of graphis in blue color.
5).Like that, assign red and blue color to all vertices and it satisfies all the constraints of way coloring problem in which .
Hence, it is clear that if any graph has odd length cycle, then it is not bipartite. And it is also proved that if a graph is bipartite then it always contains even number of cycles are only by using the graph coloring property.