Sollicitatievraag bij Google

Given a graph as input, write a java method returning boolean true if the graph is bipartitie, else false.

Antwoord op sollicitatievraag

Anoniem

30 sep 2014

iterate through all vertices, coloring each vertex one color, all of its neighbors an alternate color, and all the neighbors of those neighbors the initial color. upon completion, re-iterate through the graph and return false if any vertex has a neighbor of the same color. if re-iteration goes to completion, return true.