N-Queens CSP

Compare three CSP algorithms:
Backtracking, Forward Checking and MAC, all enhanced with MRV, Degree, and LCV heuristics

Constraint Satisfaction Problem

About

The N-Queens problem asks you to place N queens on an N×N chessboard so that no two queens share the same row, column, or diagonal. It is a classic combinatorial puzzle that grows rapidly in complexity as N increases.

We model it as a Constraint Satisfaction Problem (CSP): each row is a variable, each column position is a possible value, and the constraints rule out any placement that causes a conflict. Three algorithms — Backtracking, Forward Checking, and MAC — then search for a valid solution, each exploring the space differently.

How It Works

Three algorithms. One problem. Compare their efficiency side by side.

Backtracking

Assigns queens row by row, undoing placements when a conflict is detected. The baseline CSP approach.

Forward Checking

After each assignment, prunes conflicting values from future rows' domains to fail earlier.

MAC (AC-3)

Enforces arc-consistency after each assignment, propagating constraints across all remaining rows.

Heuristics

MRV selects the most constrained row. Degree breaks ties. LCV orders values to minimize eliminations.

Solver Demo

Configure the board and run all three algorithms instantly.

Configuration

Team

KA

Khalid Al Dosari

ZN

Zeyad bin Nazir