所以我为节点树实现了标准的深度优先搜索,其中每个节点封装了我正在解决的问题的状态,我还添加了下面的方法来检查我是否不会重复通过扩展一个节点来移动一个节点,该节点封装了我已经在某个先前节点中检查过的状态。我的问题是:这种方法是否会以某种方式改变算法的时间或空间复杂度,或者它们仍然是典型的DFS O(b ^ m)和O(bm)(这里b - 分支因子和m - 最大深度)。
//additional method which prevents us from repeating moves
public boolean checkForRepeatedMoves(Node node) {
Node nodeBeingChecked = node;
//if the current node's state is the same as the state of its parent or its parent's parent and so on.. then we are repeating a move
while (node.getParent() != null) {
if(node.getParent().getState().isEqualTo(nodeBeingChecked.getState())) {
return true;
}
node = node.getParent();
}
//if we have reached the root and no repetition is detected - return false
return false;
}