To keep track of progress, BFS colors each vertex white, gray, or black. All vertices start out white. They are colored gray upon discovery. They are painted black once all edges have been explored.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
When is a white vertex painted gray?
Back: Upon discovery.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
When is a white vertex painted black?
Back: N/A. It must be painted gray before it's painted black.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
What does a gray vertex typically represent?
Back: A vertex that is in the queue, i.e. the frontier discovery happens against.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
When is a gray vertex painted white?
Back: N/A.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
When is a gray vertex painted black?
Back: After all of its edges have been examined.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
What does a black vertex typically represent?
Back: A vertex whose edges have all been explored.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
## Breadth-First Forests
To color an entire graph black, BFS may need to be invoked multiple times. After each invocation of BFS, a new invocation can be run with any remaining white vertex as the source. Each invocation yields a **breadth-first tree**. Multiple invocations yield a **breadth-first forest**.
%%ANKI
Basic
When might white vertices remain after BFS is invoked?
Back: When there exist vertices unreachable from the last used source vertex.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1735081276213-->
END%%
%%ANKI
Basic
How many invocations of BFS are required to color a graph black?
Back: One or more.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1735081276214-->
END%%
%%ANKI
Cloze
The {1:source} of a breadth-first {2:search} is the {2:root} of a breadth-first {1:tree}.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1727042295723-->
END%%
%%ANKI
Basic
With respect to breadth-first trees, what does the predecessor of a node $N$ refer to?
Back: The node from which $N$ was discovered.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1727042295733-->
END%%
%%ANKI
Basic
With respect to breadth-first trees, what does the parent of a node $N$ refer to?
Back: The node from which $N$ was discovered.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1727042295739-->
END%%
%%ANKI
Basic
With respect to breadth-first trees, the predecessor of a node is also known as what?
Back: The parent of the node.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1727044035958-->
END%%
%%ANKI
Basic
With respect to breadth-first trees, the parent of a node is also known as what?
Back: The predecessor of the node.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).