Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the color array for the graph nodes.
DSA C#
int[] color = new int[[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Using graph.Count which is for lists, not arrays.
Using graph.Size or graph.Nodes which are invalid properties.
✗ Incorrect
The color array size should match the number of nodes, which is graph.Length in C# arrays.
2fill in blank
mediumComplete the code to initialize all colors to -1 (uncolored).
DSA C#
for (int i = 0; i < color.Length; i++) { color[i] = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 which are valid colors, not uncolored.
Using int.MinValue which is unnecessary and confusing.
✗ Incorrect
We use -1 to mark nodes as uncolored before starting the bipartite check.
3fill in blank
hardFix the error in the DFS method to assign the opposite color to neighbors.
DSA C#
color[neighbor] = color[node] [1] 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - which can produce invalid colors.
Using * which does not toggle colors.
✗ Incorrect
Using XOR (^) with 1 flips the color between 0 and 1 correctly.
4fill in blank
hardFill both blanks to check if a neighbor has the same color and return false.
DSA C#
if (color[neighbor] != [1] && color[neighbor] == color[[2]]) { return false; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with neighbor instead of node.
Checking for color[node] instead of node index.
✗ Incorrect
We check if neighbor is colored (not -1) and if its color equals the current node's color.
5fill in blank
hardFill all three blanks to complete the main bipartite check loop.
DSA C#
for (int [1] = 0; [2] < graph.Length; [3]++) { if (color[i] == -1 && !DFS(graph, i, color)) { return false; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables in loop parts causing errors.
Using variables not declared in the loop.
✗ Incorrect
The loop variable is i, used consistently in initialization, condition, and increment.
