The pseudocode to perform depth first search is in listing 1.
Listing 1: | depthfirstsearch |
No stack is explicitly used because the subroutine is recursive. The set Visited is necessary so we know when to stop in the case of cycles. The initial call should supply an empty set for Visited and a start vertex for x.