Explore Library
Code QuizAdvanced

Consistent Heuristic Check

Spot the flawed inequality used to verify a heuristic is consistent (monotonic).

Codejavascript
// A heuristic h is consistent if for every edge (n, m):
//   h(n) <= cost(n, m) + h(m)
function isConsistent(edges, h) {
  for (const { from, to, cost } of edges) {
    if (h[from] > cost + h[from]) {
      return false; // violation found
    }
  }
  return true;
}

What is the bug in this consistency check?