depth first search recursive algorithm