Explore Library
Code QuizAdvanced

Iterative Deepening Depth Limit

Find the depth-tracking mistake that breaks depth-limited search.

Codejavascript
function dls(graph, node, goal, limit) {
  if (node === goal) return true;
  if (limit <= 0) return false;
  for (const next of graph[node]) {
    if (dls(graph, next, goal, limit + 1)) return true;
  }
  return false;
}

This depth-limited search never actually stops at the intended depth. What is the bug?