Explore Library
Code QuizAdvanced

MRV Picks The Wrong Variable

The Minimum-Remaining-Values heuristic accidentally selects the most-constrained-free variable.

Codejavascript
// MRV: choose the unassigned variable with the FEWEST legal values left
function selectMRV(unassigned, domains) {
  let best = null;
  for (const v of unassigned) {
    if (best === null || domains[v].length > domains[best].length) {
      best = v;
    }
  }
  return best;
}

This heuristic keeps choosing variables with lots of options. What is the bug?