1
Graphs
Depth-First Search - DFS
Algorithm depthFirst (graph)
//
Process the keys of the graph in depth-first order.
if (empty graph)
return
set walkPtr to graph first
loop (through all vertices)
set processed to 0
end loop
createStack (stack)
loop (through vertex list)
if (vertex not processed and not in stack)
pushStack (stack, walkPtr)
set walkPtr processed to 1
end if

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
2
loop (not emptyStack(stack))
set vertex to popStack(stack)
process (vertex)
set vertex to processed
loop (through arc list)
if (arc destination not in stack)
pushStack(stack, destination)
set destination to in stack
end if
get next destination
end loop
end loop
end if
get next vertex
end loop
destroyStack(stack)
//
end dapthFirst

3
Breadth-First Search – BFS
Algorithm breadthFirst (graph)

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*