depth first search for local minima