1

I currently have a depth first search implemented as followed:

protected void algorithmLogic() {
    currentNode = ((Stack<Node>) expanded).pop();
    if(atGoal()) {
        // Goal reached so stop
        return;
    }
    else {
        visited.add(currentNode);
        if(currentNode.hasChild()) {
            for(int i=currentNode.getChildren().size()-1;i>-1;i--) {
                ((Stack<Node>) expanded).push(currentNode.getChildren().get(i));
            }
        }
    }
}

This is working on a tree on nodes.

Is it possible to edited this code in some way such that it performed iterative deepening search? Say with limit 2? I can't think of a way to track the level.

DTC
  • 87
  • 2
  • 8

1 Answers1

0

for those interested I solved this with help from this Writing a DFS with iterative deepening without recursion


In my implementation I used a hashmap with node keys and an integer representing the node level as the value.

Community
  • 1
  • 1
DTC
  • 87
  • 2
  • 8