Graph Theory37 sections · 1633 units
Open in Course

LeetCode 785 Is Graph Bipartite? - Lessons

summary

Four things to remember:

1.1. Use an array to track colors. Initialize to 1-1 for "unvisited."

2.2. The color flip trick 1 - c alternates between 00 and 11 cleanly.

3.3. Check all neighbors: if same color, return false immediately.

4.4. Handle disconnected graphs with an outer loop over all nodes.

This is the core bipartite detection pattern. Every variation uses the same idea: try to 22-color, fail if you find a conflict.