Algorithm. DFS (version 1) [00M8]

Mark all vertices unvisited
\mathsf {DFS}(G,u) =
Mark u visited
\mathsf {for} each neighbor v of u:
\mathsf {if} v is unvisited:
\mathsf {DFS}(G,v)

Notice that we implement DFS via recursion. Perhaps you have also seen a version that uses an explicit stack data structure. By using recursion, we essentially get our programming language's runtime system to keep track of the stack for us. Maintaining a stack ourselves can get annoying and messy, especially if we want to create any extra local variables during the DFS. However, a word of caution: using recursion in this way does not work so well in certain languages (where by "certain languages" I mean "Python"), especially if the graph is large.

To see if vertices s and t are connected, we can just run \mathsf {DFS}(G, s) and see if t is marked visited. Optionally, we can also stop early as soon as we find t during the DFS (left as an exercise).