Breadth-first search
BFS explores a graph in waves: first the start vertex, then all its neighbours, then their neighbours. A queue keeps the waves in order and a visited set stops cycles from sending us round in circles.
BFS explores a graph in waves: first the start vertex, then all its neighbours, then their neighbours. A queue keeps the waves in order and a visited set stops cycles from sending us round in circles.