Graph algorithms

Grid connectivity by Depth-First Search

A crossword grid is only valid if its white squares form a single connected region. If we represent the grid as a graph, with squares as nodes and edges representing adjacency, this is a graph connectivity question. We can answer this question with Depth-First Search (DFS).

Click squares to block them. Then run DFS and watch it go. Each square's border is colored when the DFS first enters it, and its interior is colored when the search exits it. As the number of movements increases, the color gets darker; so, a pale border around a dark interior means a square that was entered early and not finished until much later (that is, it has a deep subtree beneath it).

Time

earlylate
border — entered
interior — left
blocked square
never reached
tree edge (active path darker)

Call stack

empty

Counters

clock0
stack depth0
white squares0
reached0
regions
Traversal order
squaredfdepth

The mechanics