[prev] 15 [next]

Exercise 4: BFS Visiting Order

Change the above algorithm so that visited
  • is array of vertices in visiting order
  • rather than array [0..V-1] of visiting order
I.e. if we visited nodes in the order 0-3-1-4-2
  • we want visited = {0=>0, 1=>3, 2=>1, 3=>4, 4=>2}
  • rather than visited = {0=>0, 1=>2, 2=>4, 3=>1, 4=>3}