Data Structures & Algorithms Notes Page
Depth First Search goes “deep” cause it visits a vertex, then an adjacent vertex, and then that vertex’s adjacent vertex, and so on
This way, the distance from the starting vertex increases for each recursive iteration
In terms of a stack:
u is visited, recursively visit all of u ’s neighborsu ’s unvisited neighbors into the stackwfs(s)
{
push s into stack
while bag isnt empty
pop v from bag
for each (v, w) in G dp
if w is unmarked
mark w
push w into bag
}
// Recursively
dfs(v)
{
if v is unmarked
mark v
for each(v, w) in G do:
dfs(w)
}
