#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 4A::7.2.1.1 Generating All n-Tuples
#columns:Front	Back	Tags
TAOCP §7.2.1.1 Generating All n-Tuples: what does it cover?	Generating all n-tuples: mixed-radix counting (Algorithm M), the binary Gray code and its many properties (including Walsh functions and the Chinese ring puzzle), loopless generation, other Gray codes (balanced, monotonic, mixed radix), a worked example of fast search over five-letter words, and de Bruijn cycles with algorithms that build them, including prime strings and Algorithm F.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::about
TAOCP §7.2.1.1: why does it matter?	Gray codes are used in rotary encoders and error minimization; exhaustive generation is a basic tool for testing. Loopless generation teaches tight algorithm design.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::why
Gray code: what is it?	A Gray code is an ordering of all n-bit binary strings in which each string differs from the next in exactly one bit.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::definition
Gray code: Who is it named after?	Frank Gray of Bell Labs, who patented its use in 1953, though the reflected code was known earlier (it solves the Chinese ring puzzle).	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::definition
Gray code: How do I convert Gray code back to binary?	XOR the code with all its right shifts: b = g ^ (g &gt;&gt; 1) ^ (g &gt;&gt; 2) ^ ..., which takes log n steps with doubling shifts.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::definition
TAOCP §7.2.1.1: what is Algorithm M about?	Mixed-radix counting.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::algorithm
TAOCP §7.2.1.1, exercise 3 (rated M20, recommended): what is it asking?	Count how often the inner step of mixed-radix counting runs. The amortized-constant argument you will reuse all chapter.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 4 (rated 18, recommended): what is it asking?	Rewrite mixed-radix counting to count down. Easy, and useful on real machines.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 5 (rated 20, recommended): what is it asking?	Put an FFT's bit-reversed output back in order efficiently.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 12 (rated 25, recommended): what is it asking?	Generate the compositions of n through the bit strings that encode them.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 40 (rated 21, recommended): what is it asking?	Check whether a variant of the text's five-letter word search still gives correct answers.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 58 (rated 21, recommended): what is it asking?	Build an (n+1)-bit Gray cycle from an n-bit one by editing its delta sequence.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 88 (rated 25, recommended): what is it asking?	Predict what happens if you restart a Gray-code algorithm after it ends.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1, exercise 93 (rated M28, recommended): what is it asking?	Prove a de Bruijn cycle construction is correct. The stretch.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercise
TAOCP §7.2.1.1: how many exercises, and how are they rated?	112 exercises, rated 10 to HM48.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::exercises
TAOCP §7.2.1.1: what should you be comfortable with first?	<ul><li>4.1 Positional Number Systems</li><li>7.1.3 Bitwise tricks</li></ul>	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::prereqs
TAOCP §7.2.1.1: how should you work through it?	Implement binary counting, reflected Gray code (n XOR n&gt;&gt;1), and a de Bruijn sequence generator. Verify properties by brute force.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.1 cracked.guide::kind::approach
