I wrote an algorithm for searching in a graph and I used a flag to indicate whether a node was visited or not so I won’t be stuck in a loop in case there is a circle in my graph.
I later checked an algorithm book which used 3 states instead of 2 the 3rd being the “VISITING” state. I was wondering why is it there since I can perform the search without it?
It’s not strictly needed, but some algorithms which use BFS as a basic building block use this information, hence the extra state.
I guess from an educational viewpoint it’s also a benefit, since the illustrations give a better understanding of what’s going on.