Skip to content

Backtracking [mp]

Micro pattern

Description

Build candidates incrementally, recursively explore each choice, and undo mutable state before trying the next choice.

Problems

Cartesian choices

Choose one option at each position from the available alternatives.

Constrained generation

Explore only choices that can preserve a valid partial result.

Grid paths

Temporarily mark cells so the current path cannot reuse them.

Graph paths

Append a neighbor to the current path and remove it after exploring that branch.