---
title: "How Computers Solve Sudoku: Backtracking to DLX | Sudoku Flow"
description: "How Sudoku solvers work: backtracking, exact cover with Knuth's Dancing Links, and human-style solvers that explain each step with a technique."
url: https://sudokuflow.com/encyclopedia/computers/
language: en
last_modified: 2026-11-05
---

[Sudoku encyclopedia](https://sudokuflow.com/encyclopedia/) · Math and computing

# How computers solve Sudoku

Updated 2026-11-05

## Quick answer

Backtracking is a common way for programs to solve Sudoku: place a digit, carry on while the rules hold, and undo a choice when no digit fits. Donald Knuth's Algorithm X with Dancing Links applies backtracking to an exact cover model of the puzzle. Human-style hint engines work differently: they explain each step with a named technique.

## Backtracking

The solver tries a legal digit in an empty cell and carries on. If no digit leads to a solution, it undoes an earlier choice and tries another. Choosing the cell with the fewest possible digits first often makes the search much shorter.

Sources: [Wikipedia: Sudoku solving algorithms](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms), [Peter Norvig: Solving Every Sudoku Puzzle](https://www.norvig.com/sudoku.html)

## Exact cover and Dancing Links

Sudoku can be rewritten as an exact cover problem: pick placements so that every cell, and every digit in every row, column and box, is covered exactly once. In a paper from November 2000, Donald Knuth described Dancing Links, an efficient way to run his backtracking Algorithm X; applied to the exact cover model of Sudoku, it finds all solutions of a puzzle quickly.

Sources: [Wikipedia: Sudoku solving algorithms](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms), [Knuth, Dancing links (arXiv cs/0011047, 2000)](https://arxiv.org/abs/cs/0011047)

## Random search

Some programs fill the grid at random and then shuffle numbers to reduce the number of conflicts, with methods such as simulated annealing or genetic algorithms. They have been studied as alternative approaches; how well they do depends on the program and the puzzle.

Sources: [Wikipedia: Sudoku solving algorithms](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms)

## In a spreadsheet or in Python

Sudoku can be written as an integer program: 729 yes-or-no variables, one for each digit in each square, with rules that each square holds one digit and each row, column and box holds each digit once. Teachers of optimisation have used Excel's Solver on Sudoku models of this kind, and the Python library PuLP solves the same 729-variable model as a worked example. A search program written by hand can be short too: Peter Norvig's well-known essay solves Sudoku in Python with constraint propagation and search.

Sources: [Rasmussen and Weiss, Modeling Sudoku in Excel, INFORMS Transactions on Education (2007)](https://doi.org/10.1287/ited.7.3.228), [PuLP: A Sudoku Problem formulated as an LP](https://www.coin-or.org/pulp/CaseStudies/a_sudoku_problem.html), [Peter Norvig: Solving Every Sudoku Puzzle](https://www.norvig.com/sudoku.html)

## Solvers that think like people

A hint engine has a different job: not just to find the answer, but to show the next step a person can follow. Our app's engine tries human techniques in a fixed order, from the easiest, such as a hidden single, to the hardest, such as chains and almost locked sets, and uses the first one that leads to a placed digit; the harder ones work by ruling out candidates first. The hardest technique it uses on a puzzle sets that puzzle's level in the app.

Sources: [What each Sudoku difficulty level asks of you](https://sudokuflow.com/data/sudoku-difficulty-levels/)

## See also

- [Sudoku checker](https://sudokuflow.com/tools/sudoku-checker/)
- [What each Sudoku difficulty level asks of you](https://sudokuflow.com/data/sudoku-difficulty-levels/)

## Related articles

- [The mathematics of Sudoku](https://sudokuflow.com/encyclopedia/math/)
- [How Sudoku difficulty is rated](https://sudokuflow.com/encyclopedia/difficulty/)
- [Sudoku rules, explained](https://sudokuflow.com/encyclopedia/rules/)

## Sources

- [Wikipedia: Sudoku solving algorithms](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms)
- [Peter Norvig: Solving Every Sudoku Puzzle](https://www.norvig.com/sudoku.html)
- [Knuth, Dancing links (arXiv cs/0011047, 2000)](https://arxiv.org/abs/cs/0011047)
- [Rasmussen and Weiss, Modeling Sudoku in Excel, INFORMS Transactions on Education (2007)](https://doi.org/10.1287/ited.7.3.228)
- [PuLP: A Sudoku Problem formulated as an LP](https://www.coin-or.org/pulp/CaseStudies/a_sudoku_problem.html)
- [What each Sudoku difficulty level asks of you](https://sudokuflow.com/data/sudoku-difficulty-levels/)

[All articles →](https://sudokuflow.com/encyclopedia/)

![Sudoku app icon](https://sudokuflow.com/assets/app-icon.png)

## Want more boards like this?

We also make a Sudoku app for iPhone, iPad, Mac and Android. There are no ads in it at all, it works offline, and when you ask for a hint it shows you the technique instead of just filling in a number.

[App Store iPhone, iPad, Mac](https://apps.apple.com/app/apple-store/id6502922368?pt=125379530&ct=sudokuflow_web&mt=8) [Google Play Android](https://play.google.com/store/apps/details?id=com.rubigogames.sudoku&referrer=utm_source%3Dsudokuflow%26utm_medium%3Dweb%26utm_campaign%3Dsite)

Sudoku Flow is made by Rubigo Games, the developer of the Sudoku app recommended on this site.
