In the explanation of depth-first search (DFS) in Algorithms in a Nutshell (2nd edition), the author used 3 states for a vertex, say white(not visi
You are correct.
Instead of coloring a vertex gray, you can color it black, and the algorithm still works.
It is easy to see that because nowhere in the code the colors gray and black are being checked. The only check is whether a vertex is white or not (the line marked as 2). This means all the colors which aren't white are equivalent.
I'm guessing the point of using a third color here is for verbosity and/or visualization purposes. If you were to display the graph while traversing it, the third color makes it much clearer what the status of the traversal process is, i.e. which nodes are currently "being visited".