This is basically a combination of Breadth First Search and Depth First Search
You have to completely redo the previous search after each iteration, this seems inefficient however because of the way the algorithm scales a small percentage of the time is actually spent redoing searches.