BFS

Hide text Hide pseudo-code

Visit the nodes in BFS order. Begin your work from line 5 of the algorithm. The starting node s for the algorithm is node A.

Some additional problems.

Algorithm BFS(G, s)

  1. Initialize empty queue Q
  2. for each u ∈ V[G] do
  3.      visited[u] ← false
  4.      finished[u] ← false
  5. visited[s] ← true
  6. ENQUEUE(Q, s)
  7. while Q not empty do
  8.      u ← DEQUEUE(Q)
  9.      for each v ∈ Adj[u] do
  10.           if visited[v] = false then
  11.                visited[v] ← true
  12.                ENQUEUE(Q, v)
  13.      finished[u] ← true


  Created Fri Oct 30 13:52:50 EET 2009 - Powered by SVG-hut