Pergunta de entrevista da empresa Google

Write the code to check if graph is bipartite or not?

Respostas da entrevista

Sigiloso

27 de abr. de 2015

A graph is bipartite iff it does not contain any odd length cycle. We can use DFS algorithms and whenver there is back edge we need to make an extra assertion whether it create an odd length cycle or not. Simple way to implement is to give visited nodes a label 1 and 2 alternatively i.e if current node has label 1, give label 2 to next neighbour of current node. If back is from node of some label to node with same label then its making odd length cycle.

Sigiloso

30 de jun. de 2016

u can also use graph coloring to find if it is bipartite or not