DFS

Recursive version (naturally use stack)

Pseudo code

DFS (graph G, start vertex v)
    Mark v as explored
    for all edges from v to w in G.adjacentEdges(v) do
        if vertex w is not labeled as explored then
            recursively call DFS(G,w)

Reference

Wiki Standford algorithm course