A bipartite graph is a graph whose nodes can be divided into two groups so that no edge connects nodes within the same group.
Click to reveal answer
beginner
Which method is commonly used to check if a graph is bipartite?
We use graph coloring with two colors or Breadth-First Search (BFS) or Depth-First Search (DFS) to assign colors and check for conflicts.
Click to reveal answer
beginner
In bipartite graph check, what does it mean if a node's neighbor has the same color?
It means the graph is not bipartite because two connected nodes share the same group, which is not allowed.
Click to reveal answer
beginner
What data structure is useful to keep track of node colors during bipartite check?
An array or map to store colors for each node, typically using two values like 0 and 1 or -1 for uncolored.
Click to reveal answer
intermediate
Why do we need to check all nodes in the graph when checking bipartiteness?
Because the graph might be disconnected, so we must check each connected component separately.
Click to reveal answer
What is the main property of a bipartite graph?
ANodes can be split into two groups with no edges inside the same group
BEvery node connects to every other node
CGraph has no edges
DGraph contains cycles only
✗ Incorrect
A bipartite graph's nodes can be divided into two groups with edges only between groups.
Which algorithm is commonly used to color nodes for bipartite check?
AFloyd-Warshall algorithm
BDijkstra's algorithm
CPrim's algorithm
DBreadth-First Search (BFS)
✗ Incorrect
BFS helps assign colors level by level to check bipartiteness.
If a neighbor node has the same color during bipartite check, what does it mean?
AGraph is bipartite
BGraph is not bipartite
CGraph is disconnected
DGraph is complete
✗ Incorrect
Same color neighbors mean the graph is not bipartite.
What color value is usually used to mark uncolored nodes?
A-1
B1
C0
D2
✗ Incorrect
Uncolored nodes are often marked with -1 to distinguish from colored nodes.
Why must we check all nodes in the graph for bipartite property?
ABecause nodes have weights
BBecause all nodes have edges
CBecause graph might be disconnected
DBecause graph is always connected
✗ Incorrect
Disconnected graphs have multiple components that must be checked separately.
Explain how to check if a graph is bipartite using BFS.
Think about coloring nodes level by level and checking conflicts.
You got /6 concepts.
Describe why a graph with an odd-length cycle cannot be bipartite.
Consider coloring nodes around a cycle and what happens at the end.
You got /4 concepts.
Practice
(1/5)
1. What does it mean if a graph is bipartite?
easy
A. Its vertices can be divided into two groups with no edges inside the same group
B. It has an equal number of vertices and edges
C. It contains at least one cycle
D. All vertices have the same degree
Solution
Step 1: Understand bipartite graph definition
A bipartite graph can be split into two sets where no edges connect vertices within the same set.
Step 2: Compare options with definition
Only Its vertices can be divided into two groups with no edges inside the same group matches this definition exactly.
Final Answer:
Its vertices can be divided into two groups with no edges inside the same group -> Option A
Quick Check:
Bipartite = Two groups, no internal edges [OK]
Hint: Bipartite means two groups with no edges inside groups [OK]
Common Mistakes:
Confusing bipartite with equal vertices and edges
Thinking bipartite means no cycles
Assuming all vertices have same degree
2. Which TypeScript data structure is best to represent a graph for bipartite check?
easy
A. Adjacency list using Map
B. Array of numbers
C. String array
D. Single number variable
Solution
Step 1: Identify graph representation needs
We need to store edges for each vertex efficiently to check bipartite property.
Step 2: Choose suitable data structure
An adjacency list using Map stores neighbors for each vertex clearly and is efficient.
Final Answer:
Adjacency list using Map<number, number[]> -> Option A
Quick Check:
Graph as adjacency list = Map [OK]
Hint: Use adjacency list (Map) for graph edges [OK]
Common Mistakes:
Using simple arrays without edge info
Using strings which don't represent graph
Using single variable instead of structure
3. What is the output of this TypeScript code that checks if a graph is bipartite?
const graph = new Map([
[0, [1, 3]],
[1, [0, 2]],
[2, [1, 3]],
[3, [0, 2]]
]);
function isBipartite(graph: Map): boolean {
const color = new Map();
for (const node of graph.keys()) {
if (!color.has(node)) {
const queue = [node];
color.set(node, 0);
while (queue.length) {
const u = queue.shift()!;
for (const v of graph.get(u)!) {
if (!color.has(v)) {
color.set(v, 1 - color.get(u)!);
queue.push(v);
} else if (color.get(v) === color.get(u)) {
return false;
}
}
}
}
}
return true;
}
console.log(isBipartite(graph));
medium
A. false
B. true
C. undefined
D. SyntaxError
Solution
Step 1: Analyze graph structure
The graph is a square cycle: 0-1-2-3-0, which is an even cycle and bipartite.
Step 2: Trace BFS coloring
Starting from node 0 with color 0, neighbors get color 1, their neighbors color 0, no conflicts found.
Final Answer:
true -> Option B
Quick Check:
Even cycle graph is bipartite = true [OK]
Hint: Even cycles are bipartite, odd cycles are not [OK]
Common Mistakes:
Assuming all cycles are not bipartite
Confusing color assignment logic
Missing BFS queue processing
4. Find the bug in this TypeScript function that checks if a graph is bipartite:
function isBipartite(graph: Map): boolean {
const color = new Map();
for (const node of graph.keys()) {
if (!color.has(node)) {
const queue = [node];
color.set(node, 0);
while (queue.length) {
const u = queue.shift()!;
for (const v of graph.get(u)!) {
if (!color.has(v)) {
color.set(v, color.get(u)!);
queue.push(v);
} else if (color.get(v) === color.get(u)) {
return false;
}
}
}
}
}
return true;
}
medium
A. Missing return type boolean
B. queue.shift()! should be queue.pop()
C. color.set(v, color.get(u)!) should be color.set(v, 1 - color.get(u)!)
D. graph.get(u)! should be graph.get(v)!
Solution
Step 1: Identify color assignment error
The code assigns the same color to neighbors, which breaks bipartite logic.
Step 2: Correct color assignment
Neighbors must get opposite color: 1 - color of current node.