Explore Library
Code QuizAdvanced

Greedy Best-First Node Selection

Find why this greedy best-first search ignores its heuristic.

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

This is supposed to pick the greedy best-first node, but it behaves like uniform-cost. What is the bug?