在实现DFS和BFS时,CLRS作者为每个顶点区分3种颜色 - 灰色,黑色和白色.我知道黑色和白色表示节点是否被访问过.为什么我们需要灰色?
我的猜测是检测周期,但是我们还能检测出只有黑白的周期(即没有灰色)吗?
algorithm breadth-first-search depth-first-search clrs graph-algorithm
algorithm ×1
breadth-first-search ×1
clrs ×1
depth-first-search ×1
graph-algorithm ×1