Explore Library
Code QuizAdvanced

A* f = g + h Evaluation

Identify why this A* node selection uses the wrong evaluation function.

Codejavascript
// each item: { node, g, h }  (g = cost so far, h = heuristic estimate)
function selectNext(frontier) {
  frontier.sort((a, b) => a.h - b.h);
  return frontier[0];
}

This is meant to implement A* selection but loses optimality. What is the bug?