Pattern Databases

GATE Relevance: Low

Prerequisites

🎯 Learning Objectives

  • Understand pattern databases as precomputed lookup tables
  • Explain abstract state spaces and how they reduce problem size
  • Distinguish additive (disjoint) pattern databases from non-additive ones
  • Know real-world applications (15-puzzle, 24-puzzle, Rubik’s Cube)

1. The Concept

A pattern database (PDB) stores the exact solution cost of an abstract version of each state. Instead of computing h(n) on the fly (like Manhattan distance), we precompute h(n) for every abstract state and store the results in a lookup table.

At search time, we look up the abstract version of the current state in the table. This gives us a perfect heuristic for the abstract problem, which is an admissible heuristic for the original problem (since the abstract problem is a relaxation).

2. Abstract State Spaces

To create a pattern database, we define an abstraction function φ that maps the original state space to a smaller abstract state space.

For the 15-puzzle, a common abstraction is to keep only a subset of tiles and treat the others as identical “don’t care” symbols.

15-Puzzle Abstraction Example
Original state:
 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15  _

Pattern: Keep tiles {1, 2, 3, 4, 5, 6, 7, 8}, replace rest with X:
 1  2  3  4
 5  6  7  8
 X  X  X  X
 X  X  X  _

The abstract state space has only the positions of tiles 1–8 and the blank. The number of abstract states is much smaller: approximately 16!/(8! · 1) ≈ 518 million for this partition (still large, but the 8-tile pattern for the 15-puzzle is manageable).

3. Building a Pattern Database

  1. Choose a pattern (subset of tiles/components to track).
  2. Define the abstract goal: the goal positions of the pattern tiles.
  3. Run backward BFS from the abstract goal in the abstract state space. For each abstract state encountered, record the distance (number of moves) from the goal.
  4. Store in a hash table or array indexed by the abstract state encoding.

Once built, the PDB is used during search: for any state n, compute φ(n) and look up PDB[φ(n)] to get h(n).

4. Additive (Disjoint) Pattern Databases

A major breakthrough was disjoint pattern databases (Korf & Felner, 2002). If two patterns use disjoint sets of tiles, their costs can be added together and the sum is still admissible.

Disjoint PDBs for 15-Puzzle

Partition the 15 tiles into two groups:

  • PDB-A: Tiles {1, 2, 3, 4, 5, 6, 7, 8} → cost to move these to goal positions
  • PDB-B: Tiles {9, 10, 11, 12, 13, 14, 15} → cost to move these to goal positions

h(n) = PDB-A(φA(n)) + PDB-B(φB(n))

This is admissible because each move moves at most one tile, and we’re counting moves for disjoint tile sets — no double counting.

⚠ Non-Disjoint Patterns Cannot Be Added

If two patterns share tiles, adding their costs may overcount, violating admissibility. Use max() for overlapping patterns instead.

5. Practical Results

Heuristic Comparison for 15-Puzzle (Random Instances)
HeuristicAvg. Nodes ExpandedTime
Manhattan Distance~400,000~5 sec
Single PDB (7-8 split)~40,000~0.5 sec
Disjoint Additive PDB (7-8 split)~600~0.01 sec

Disjoint additive PDBs gave a ~600x speedup over Manhattan distance for the 15-puzzle, and enabled solutions of the 24-puzzle that were previously intractable.

6. Worked Examples

Example 1: Simple PDB Lookup

Consider a 3×3 sliding puzzle with tiles {1, 2, 3, _, X, X, X, X, X} as the pattern. The abstract goal is tiles 1, 2, 3 in positions (0,0), (0,1), (0,2).

Current abstract state: 
 _  1  3
 X  2  X
 X  X  X

PDB lookup: This configuration requires 3 moves to reach:
 1  2  3       (move 1→left, move blank down, ... )
 X  X  X
 X  X  X

h(n) = PDB[abstract_state] = 3
Example 2: Additive vs Max for Two PDBs

PDB-1 (tiles {A, B}): h1(n) = 4. PDB-2 (tiles {C, D}): h2(n) = 3.

Disjoint → h(n) = 4 + 3 = 7.

If overlapping → h(n) = max(4, 3) = 4.

The additive version is much more informative, highlighting why disjoint partitions are preferred.

Summary

  • Pattern databases precompute exact costs in abstract state spaces.
  • Lookup is O(1), making them very fast during search.
  • Disjoint (additive) PDBs can be summed while maintaining admissibility.
  • Enabled solving 15-puzzle ~600x faster and made 24-puzzle tractable.
  • Tradeoff: requires memory to store the PDB (build once, use many times).