White Vertex
In a graph coloring problem, a white vertex refers to a vertex that is uncolored or “white”. Algorithms will aim to color vertices while maintaining certain constraints, leaving some vertices potentially white or uncolored.
Some examples:
Vertex coloring - Each vertex should be colored differently than its neighbors. Some vertices may remain white if no valid color is available.
Bipartite matching - Finding a matching from one partition to the other. Unmatched vertices remain white.
Map coloring - Assign colors to regions with no adjacent same-colored regions. More colors may be needed to color the entire graph.
Java - Bipartite matching:
|
|
C++ - Map coloring:
|
|
Python - Vertex coloring:
|
|
Tracking white vertices helps model unprocessed elements in constraints satisfaction and graph problems.
In graph theory, particularly in the context of traversal algorithms like Depth-First Search (DFS), a “white vertex” refers to an unvisited or undiscovered node. When you begin the traversal, all vertices are initially white. As the traversal progresses, vertices change their color to represent their states. A white vertex turns “gray” when it is discovered but not yet fully explored, and “black” when it and its adjacent vertices are completely explored.
In the context of Depth-First Search (DFS) in graph theory, a white vertex is one that has not been visited yet. During DFS, vertices go through three states: white (unvisited), gray (visited but not finished), and black (visited and finished).
Visual Representation:
Let’s consider a simple graph with vertices A, B, C, and D.
A----B
| |
| |
D----C
Initially, all vertices are white (unvisited):
(White) A----B (White) | | | | (White) D----C (White)
Starting DFS at A, A becomes gray:
(Gray) A----B (White) | | | | (White) D----C (White)
After visiting B, B becomes gray while A remains gray:
(Gray) A----B (Gray) | | | | (White) D----C (White)
Eventually, after visiting all neighbors, vertices turn black:
(Black) A----B (Black) | | | | (Black) D----C (Black)
Key Takeaway:
White vertices are those that have yet to be visited in the DFS process. Understanding the state of each vertex at different stages of DFS helps in graph traversal, path finding, and cycle detection.
Solution
Below are code examples that demonstrate the concept of a white vertex in the context of DFS in Java, C++, and Python.
Java
|
|
C++
|
|
Python
|
|
Key Takeaways
- A white vertex in the DFS context means an undiscovered or unvisited node.
- The
color
array in the code keeps track of the state of each vertex: white, gray, or black. - As DFS proceeds, vertices transition from white to gray and finally to black.