Recall BFS for the general algorithm details.

Differences compared to BFS for trees

  • a visited array is required.
  • there will not be a root node, as such, a given source node must be provided.

Visualisation

Implementation