Python: Write a class function to tell if the graph is bipartite. Start with vertex 0. You can access the adjacency list for a vertex v with: self.adjacency_list[v] — def is_bipartite(self): """ Returns true if graph is bipartite :rtype: bool """ colorings = {} to_visit = queue.Queue() to_visit.put(0) colorings[0] = 0 while not to_visit.empty(): v = to_visit.get() for u in self.adjacency_list[v]: if u not in colorings: colorings[u] = 1 - colorings[v] to_visit.put(u) elif colorings[u] == colorings[v]: return False return True
G
1.2K
Google Interview
This flashcard deck made by jwasham contains knowledge about google interview. For more details, please follow https://github.com/jwasham/google-interview-university