liveBook · Manning

Reducer

As explained in Fabulous Adventures in Data Structures and Algorithms

Reducer is the book's one-member interface for transforming an attempt by eliminating possible values without guessing.

A reducer transforms an attempt by eliminating possible values without guessing. In graph coloring, it removes a color from every neighbor of a node whose remaining possibilities have narrowed to one. section 8.5.2

A reducer fits between an attempt and a backtracking search:

  • Accept an attempt: a multidictionary from nodes to their possible colors. section 8.5.2
  • Find nodes with exactly one remaining value and remove that value from their neighbors. section 8.5.2
  • Repeat reductions while new single-value nodes appear, stopping when no further progress is possible. section 8.5.2

Graph coloring and Sudoku

GraphColorReducer<N, C> implements IReducer<N, C> and receives a graph describing which nodes constrain one another. The same reducer structure solves Sudoku by treating cells as nodes and digits as possible colors; reduction propagates fixed digits before recursive guesses explore the remaining possibilities.

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Implements repeated constraint propagation in C#, while deferring the remaining choices to recursive backtracking.
Examples
Uses graph-coloring attempts and a Sudoku puzzle to demonstrate propagation before recursive guessing.
What it assumes
Assumes attempts, graphs, possible-value collections, and recursive backtracking, while defining the reducer’s interface and role.
What you can do after
Build a generic reducer that prunes impossible values before a backtracking solver makes guesses.
How it connects
Connects graph coloring, backtracking search, constraint propagation, multidictionaries, and Sudoku.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.