Search for the end of a path in the d-dimensional grid and in other graphs