--- license: mit pretty_name: "Sudoku Solver Benchmark (backtracking vs MRV vs constraint propagation)" language: - en tags: - sudoku - solver - backtracking - constraint-propagation - mrv-heuristic - benchmark - search task_categories: - other size_categories: - n<1K configs: - config_name: strategies data_files: data/sudoku-strategies.json --- # Sudoku Solver Benchmark — Backtracking vs MRV vs Constraint Propagation Search cost (recursive calls / "nodes") and solve time for three ways to solve a 9×9 Sudoku, measured on the **same shipped engine** that powers the [LK Forge Sudoku Solver](https://lkforge.com/tools/puzzles/sudoku-solver/), across a reproducible, seed-generated corpus of easy → expert puzzles. All three strategies are asserted to return the same correct solution, so no wrong number ships. - **How the solver works:** https://lkforge.com/tools/puzzles/sudoku-solver/how-the-sudoku-solver-works.html - **Try it:** https://lkforge.com/tools/puzzles/sudoku-solver/ - **Producer:** [LK Forge](https://lkforge.com) — client-side AI games, solvers, and tools. ## Headline numbers (overall averages) | Strategy | Avg search nodes | Avg solve time | |---|---|---| | Naive backtracking (next-empty cell) | **28,835** | 2.536 ms | | MRV backtracking (most-constrained cell first) | **177** | 0.220 ms | | Constraint propagation (naked + hidden singles) | **2** | 0.118 ms | So the **MRV heuristic cuts search ~163× vs naive backtracking**, and **constraint propagation solves a typical puzzle in ~2 nodes** — deducing the answer with almost no guessing, the same reasoning the solver's hint engine explains. ## Files - `data/sudoku-strategies.json` — per-difficulty (easy/medium/hard/expert) and overall `avgMs` and `avgNodes` for each of the three strategies. ## Method - **Corpus:** puzzles produced by the shipped generator with fixed seeds → reproducible. - **Node count** = recursive solver calls (a machine-independent measure of search effort). - **Strategies:** (1) naive backtracking in the shipped cell order; (2) MRV — always branch on the cell with the fewest candidates; (3) logic — apply naked + hidden singles as far as possible before guessing. - **Correctness gate:** all three must return the identical, valid solution for every puzzle. ## Reproduce ```bash node benchmark.js # runs the shipped engine.js over the seeded corpus ``` ## Citation > LK Forge (2026). *Sudoku Solver Benchmark — Backtracking vs MRV vs Constraint Propagation.* > https://lkforge.com/tools/puzzles/sudoku-solver/ Everything runs client-side, no login, no tracking.