Given G Pick an unvisited vertex v, remember the rest Recurse on vertices adjacent to v
DFS(G) foreach v in V visited(v) = False pred(v) = NIL time = 0 foreach u in V if not visited(u) then Visit(u)
Visit(u) visited(u) = True time = time + 1 discover(u) = time foreach v in Adj[u] ; if not visited(v) then pred(v) = u Visit(v) time = time + 1 finished(u) = time