#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 4A::7.2.1.2 Generating All Permutations
#columns:Front	Back	Tags
TAOCP §7.2.1.2 Generating All Permutations: what does it cover?	Generating all permutations: lexicographic order (Algorithm L, which also handles multisets), plain changes by adjacent swaps (Algorithm P), Heap's method and other single-swap schemes, Sims tables for permutation groups, alphametics as a search application, generating with early cutoffs (Algorithm X), topological sorts, and timing comparisons of the methods in MMIX.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::about
TAOCP §7.2.1.2: why does it matter?	next_permutation is a standard library function and a classic interview question. Choosing the right generator matters when you brute force.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::why
TAOCP §7.2.1.2: what is Algorithm L about?	Lexicographic order, which also handles multisets.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::algorithm
TAOCP §7.2.1.2: what is Algorithm P about?	Plain changes by adjacent swaps.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::algorithm
TAOCP §7.2.1.2: what is Algorithm X about?	Generating with early cutoffs.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::algorithm
TAOCP §7.2.1.2: what traps should you watch for?	<ul><li>Lexicographic generation with duplicates: handle multisets correctly.</li></ul>	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::traps
TAOCP §7.2.1.2, exercise 1 (rated 20, recommended): what is it asking?	Speed up lexicographic next-permutation for the common case. The kind of tuning that matters in real loops.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 3 (rated M21, recommended): what is it asking?	Compute the rank of a permutation in lexicographic order.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 12 (rated M23, recommended): what is it asking?	Find the millionth permutation of ten digits under three different algorithms, using mixed-radix arithmetic.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 17 (rated 20, recommended): what is it asking?	Keep the inverse permutation updated while running plain changes.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 49 (rated 28, recommended): what is it asking?	Rework the alphametic solver to choose digits in a smarter order. Search ordering in practice.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 85 (rated 25, recommended): what is it asking?	Rank and unrank permutations in linear time. Standard trick for indexing permutations in tables.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 107 (rated 30, recommended): what is it asking?	Topswops, Conway's card game. Explore it with code.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2, exercise 41 (rated M33, recommended): what is it asking?	Generate all r-variations with one swap per step by generalizing Heap's method. The stretch.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercise
TAOCP §7.2.1.2: how many exercises, and how are they rated?	113 exercises, rated M15 to 48.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::exercises
TAOCP §7.2.1.2: what should you be comfortable with first?	<ul><li>7.2.1.1 Generating All n-Tuples</li><li>1.3.3 Permutations</li></ul>	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::prereqs
TAOCP §7.2.1.2: how should you work through it?	Implement lexicographic next-permutation, plain changes, and Heap's method. Count swaps per permutation and benchmark. Look up change ringing; it is permutation generation with church bells, and plain changes are exactly what this section covers.	cracked.guide cracked.guide::phase::taocp-4a cracked.guide::section::7.2.1.2 cracked.guide::kind::approach
