The DFS Algorithm

Recall the BFS algorithm:

BFS(G,s)
   for each u ∈ V[G]-{s} do
      open[u] = true
      d[u] = ∞ 
      pred[u] = null
   open[s] = false
   d[s] = 0
   pred[s] = null
   Q = {s}
   while Q ≠ {} do
      u = Remove[Q]
      for each v ∈ Adj[u] do
         if open[v] = true
            then open[v] = false
                 d[v] = d[u] + 1
                 pred[v] = u
                 Add(Q,v)