Home / Solver & solutions
Solver & solutions

Sliding Puzzle Solver — Algorithm Comparison

A* vs IDA*, Manhattan vs walking distance, vs additive pattern databases. Six well-known algorithms for solving sliding puzzles, what each is good for, and where each falls over.

Updated 2026-05-20 8 min read

If you are implementing a sliding puzzle solver and are not sure which algorithm to use, this article compares six well-known ones across speed, memory, code complexity, and the board size they comfortably handle. The answers are different for the 3×3, the 4×4, and the 5×5.

1. Breadth-first search (BFS)

The dumbest correct algorithm. Explore states level by level until you find the goal.

2. A* with Manhattan distance

The first real algorithm. Same structure as BFS but states are popped from a priority queue ordered by f = g + h, where h is the Manhattan distance heuristic.

3. A* with Manhattan + linear conflict

Add 2 moves to the heuristic for every pair of tiles in the same row that are both in their goal row but in the wrong order (similarly for columns). They will need to pass each other, which Manhattan distance cannot see.

4. IDA* with Manhattan + linear conflict

Iterative-deepening A*. Do depth-limited DFS using f-cost as the depth measure, raising the limit each iteration. Trades memory for time by re-exploring.

5. IDA* with walking distance

Walking distance is a tighter heuristic. Precompute, for each tile arrangement projected onto rows only, the minimum number of row-swap operations to put each tile in its correct row. Same for columns. Add.

It captures something Manhattan misses: tiles in the same row "fighting" for the same slot.

6. IDA* with additive disjoint pattern databases

The strongest known heuristic for sliding puzzles. Partition the tiles into disjoint groups (a common 15-puzzle partition is 7+8, or 5+5+5). Precompute, for each group, the cost of permuting the group's tiles to their goal positions over all possible arrangements of that group. At search time, look up each group's contribution and sum.

Summary recommendations

If you are writing a solver today:

What about machine learning?

A reasonable question in 2026. Neural network heuristics have been studied since at least 2014 and can produce fast heuristics for sliding puzzles. The catch is that they are typically not admissible — they can overestimate, which means the resulting algorithm is no longer guaranteed to be optimal. For app developers who want guaranteed-optimal solutions for difficulty calibration, classical pattern databases remain the right tool.

For research interest, pattern databases trained by a neural network produce slight speedups on the hardest 15-puzzle instances. Useful for academic papers, marginal for shipping software.

What goes in a real app

A shipping mobile app that needs a solver for hint generation almost always lands on:

That is the right pragmatic stack for a calm phone app. Slide Puzzle's hint button works exactly this way.