Prefer BFS to DFS while reseting indexes since we are limited by stack depth and not heap size.