BFS through each connected component. Assign alternating colors. If a conflict appears, return false.
function isBipartite(graph):
n = len(graph)
color = array of size n, filled with -1
for start from 0 to n-1:
if color[start] != -1:
continue
color[start] = 0
queue = [start]
while queue is not empty:
node = queue.pop_front()
for neighbor in graph[node]:
if color[neighbor] == -1:
color[neighbor] = 1 - color[node]
queue.push(neighbor)
elif color[neighbor] == color[node]:
return false
return true
time, space.