Depth-first search with recursion.