Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

Forward Checking

After each assignment, remove now-impossible values from neighbouring variables.

The idea

Plain backtracking only notices a problem when it reaches it. Forward checking looks ahead: when a variable is assigned, it deletes the conflicting values from the domains of connected variables. If any domain becomes empty, it backtracks immediately.

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

WANTQNSWVSAT
  • red
  • green
  • blue
  • being assigned

Forward checking: assign a colour, then immediately remove it from neighbours' options. If a neighbour has none left, back up at once.

1/9

Compare the number of tries between plain backtracking and forward checking.

Step by step

  1. 1Assign a value to a variable.
  2. 2For every unassigned neighbour, remove values that now conflict.
  3. 3If a neighbour has no values left, undo and try another value.
  4. 4Otherwise continue with the next variable.

Where it is used

A cheap, effective speed-up for backtracking on any CSP.

Watch out for

It only checks neighbours of the last assignment, so it can miss conflicts that AC-3 would find.

Related