Pseudo-code
1 | BDS(node N0, int cut_off_depth): |
Explanation
Why search from G to H?
If G (the goal state) can reach H (the set of states at depth cur_limit
from N0), then there exists a path from N0 to G through H. This is because H contains all states that are exactly cur_limit
steps away from N0, and if G can reach any of these states, it implies that there is a valid path from N0 to G.
Why cur_limit + 1
?
If G can reach H with a depth limit of cur_limit
, the total depth L
from N0 to G is 2 * cur_limit
, which is even. However, this doesn’t account for cases where the total depth L
is odd. By also checking with a depth limit of cur_limit + 1
, we can capture scenarios where the path from N0 to G has an odd length, specifically 2 * cur_limit + 1
. This ensures that we do not miss any potential paths due to the parity of the total depth.