Explain briefly the use of color codes in BFS algorithm. Explain what each color represents.
Color Codes In BFS algortithm
BFS stands for Breadth First Search, which is used for graph and tree traversal or searching. While traversing the the graph nodes the BFS algorithm assign color to each node. In simple words, to keep track of all nodes the BFS assign black, white and grey color to eac node.
Intially all the nodes are having white color, indicating that, any of the is not being traversed yet. The white vertix or node is also called as undiscovered node.
A node is assigned color grey when the node is intially discovered and color black is assigned when the BFS algorithm completely explored that vertice or node.
In simple words, once the node is assigned color black, this indicates that all the adjacent nodes of the current node are not white while grey color node indicates that there may some white nodes which are need to be explored or traversed.
Get Answers For Free
Most questions answered within 1 hours.