#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 4B::7.2.2 Backtrack Programming (part 1)
#columns:Front	Back	Tags
TAOCP §7.2.2 Backtrack Programming (part 1): what does it cover?	Part 1 covers the first two-thirds of 7.2.2 (pages 30 to 45). It starts with the basic backtrack scheme (Algorithm B) on the n queens problem, then Walker's bitwise version (Algorithm W), Langford pairs with a linked list of unused values (Algorithm L), and word rectangles built column by column with a trie. After that comes a long case study: searching for commafree codes with dynamic ordering of choices, sequential (array-based) lists with cheap deletion and undeletion, and a general memory-stamping scheme for doing and undoing changes (Algorithm C).	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::about
TAOCP §7.2.2 (part 1): why does it matter?	Backtracking solves constraint problems from sudoku to scheduling to regex matching. It is also a constant source of LeetCode problems.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::why
TAOCP §7.2.2 (part 1): what is Algorithm B about?	The basic backtrack scheme.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::algorithm
TAOCP §7.2.2 (part 1): what is Algorithm W about?	Walker's bitwise version.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::algorithm
TAOCP §7.2.2 (part 1): what is Algorithm L about?	Langford pairs with a linked list of unused values.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::algorithm
TAOCP §7.2.2 (part 1): what is Algorithm C about?	A general memory-stamping scheme for doing and undoing changes.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::algorithm
TAOCP §7.2.2 (part 1), a common trap: “Choosing a bad order of variables.” What's the catch?	The commafree search shows how much dynamic ordering (most constrained choice first) helps.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::trap
TAOCP §7.2.2 (part 1), a common trap: “Assuming linked lists are always the right undo structure.” What's the catch?	The text's sequential lists, with swap-to-delete, are often faster.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::trap
TAOCP §7.2.2 (part 1): what traps should you watch for?	<ul><li>Forgetting to undo state on the way back.</li></ul>	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::traps
TAOCP §7.2.2 (part 1), exercise 5 (rated 20, recommended): what is it asking?	Rewrite Algorithm B as a recursive procedure, and think about why the book prefers the iterative form.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 10 (rated 22, recommended): what is it asking?	Adapt Walker's method to n queens with n-bit masks. The classic fast queens counter.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 20 (rated 21, recommended): what is it asking?	Add a forcing rule to the Langford pair search, so values that must go in now are placed at once.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 25 (rated 25, recommended): what is it asking?	Use orthogonal lists to find all words with a given letter in a given position, and speed up the word rectangle search with them.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 35 (rated 22, recommended): what is it asking?	Design an incremental test that accepts a new four-letter word only if the code stays commafree.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 40 (rated 15, recommended): what is it asking?	Think about why these sequential list structures were left out of the Vol 1 section on sequential allocation.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 44 (rated 25, recommended): what is it asking?	Write out the low-level candidate selection step of the commafree search, using the reversible store routine.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1), exercise 37 (rated M30, recommended): what is it asking?	The stretch: understand and prove Eastman's construction of a maximum commafree code for odd block lengths.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercise
TAOCP §7.2.2 (part 1): how many exercises, and how are they rated?	48 exercises, rated 10 to HM42.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::exercises
TAOCP §7.2.2 (part 1): what should you be comfortable with first?	<ul><li>7.2.1 Generating Basic Combinatorial Patterns</li></ul>	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::prereqs
TAOCP §7.2.2 (part 1): how should you work through it?	Implement n queens twice: once as Algorithm B with plain arrays, and once with Walker's bitmask trick. Count solutions up to n = 14 or so. Then do Langford pairs with Algorithm L. Read the commafree case study slowly; the doing/undoing scheme is the idea you will reuse all through 7.2.2.1 and 7.2.2.2.	cracked.guide cracked.guide::phase::taocp-4b cracked.guide::section::7.2.2 cracked.guide::kind::approach
