Recall BFS to for the basic idea.

Differences compared to BFS for trees

  • a visited array is required.
  • there will not be a root node, instead, a given source must me.

Visualisation

Implementation