这只是固有的,因为我的状态图的分支因子是4(因此在Iterative-Deepening的任何阶段它将是4 ^ k并且比以前指数级慢?)
或者有什么我错过了吗?
这是我的DFS方法:
/**
* CONTAINS Deja-Vu checker!
*/
private static Node depthFirst(Node start, String goal, ArrayList<Node> visited, int depth)
{
//END-case
if (start.getConfig().equals(goal)){
return start;
}
else if (depth == 0){
//IF DEPTH REACHED BUT NOT FOUND GOAL
return null;
}
//main sequence
ArrayList<Node> neighbours = start.getNeighbours();
for (Node neighbour : neighbours){
//Deja-Vu check
if (!(visited.contains(neighbour))){
visited.add(neighbour);
//my version of linked list
start.append(depthFirst(neighbour, goal, visited, (depth-1)));
//FALSE-PATH DENIAL
if (start.route != null){
return start;
}
}
}
//false path
return null;
}
这包含在我的Iterative Deepening方法中:
/**
* ASSUMES limit is 1000
*/
private static Node IterativeDeepening(Node start, String goal)
{
Node route;
for (int depth = 1; (depth < 1000); depth++){
route = depthFirst(start, goal, (new ArrayList<Node>()), depth);
if (route != null){
return route;
}
}
//if all routes are null
return null;
}