Backtracking Algorithms

Algorithms that explore candidates and abandon partial solutions.

  • JSON3,606 B
  • YAML2,575 B · −29%
  • TOON2,161 B · −40%

Classic problems solved by backtracking: N-Queens, Sudoku, subset sum, graph coloring, Hamiltonian cycles and maze solving, extended with permutations, combination sum, word search, the knight's tour, palindrome partitioning and generating parentheses.

Use it when

  • You need a canonical example for the backtracking technique.
  • You are practicing constraint-satisfaction problems.

Watch out for

  • Backtracking has exponential worst-case cost; pruning decides whether it is practical.
  • For optimization problems, dynamic programming or branch and bound may be better.

The data

ProblemDescription
N-QueensPlace N non-attacking queens on an NxN chessboard.
Sudoku SolverFill a 9x9 grid satisfying row, column, and box constraints.
Subset SumFind a subset whose sum equals a target value.
Graph ColoringAssign colors to vertices so adjacent vertices differ.
Hamiltonian CycleFind a cycle that visits every vertex exactly once.
Maze SolvingFind a path from start to goal through a maze.
PermutationsGenerate all orderings of a set by fixing an element and recursing on the rest.
Combination SumFind all combinations of numbers that add up to a target, reusing numbers where allowed.
Word SearchFind a word in a grid by moving to adjacent cells without reusing a cell.
Knight's TourMove a knight so it visits every square of a chessboard exactly once.
Palindrome PartitioningSplit a string into parts so every part is a palindrome.
Generate ParenthesesProduce all well-formed strings of n pairs of parentheses.

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
dataproblemstringN-Queens
datadescriptionstringPlace N non-attacking queens on an NxN chessboa…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/backtracking-algorithms?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/backtracking-algorithms.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • algorithms
  • backtracking
  • recursion

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets