#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 3::5.1.1 Inversions
#columns:Front	Back	Tags
TAOCP §5.1.1 Inversions: what does it cover?	An inversion is a pair of elements that are out of order. Knuth studies the inversion table of a permutation, which encodes it uniquely, and counts how many permutations have a given number of inversions, with generating functions.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::about
TAOCP §5.1.1: why does it matter?	The number of inversions is exactly how much work insertion sort and bubble sort do, and counting inversions is a classic merge-sort interview problem.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::why
TAOCP §5.1.1, fill in the blank:<br>Then count inversions in <span class="cg-blank">&nbsp;</span> with a modified merge sort.	Then count inversions in <b>O(n log n)</b> with a modified merge sort.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::complexity
TAOCP §5.1.1, a common trap: “There are several conventions for inversion tables.” What's the catch?	Stick to Knuth's within this volume.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::trap
TAOCP §5.1.1, exercise 1 (rated 10): what is it asking?	Convert a permutation to its inversion table and back by hand. Five minutes, and it fixes the convention for the whole chapter.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 4 (rated 20, recommended): what is it asking?	Rebuild a permutation from its inversion table with a linked list. Implement it; you will use it to test exercise 6.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 6 (rated 26, recommended): what is it asking?	Compute the inversion table in n log n time. The same divide-and-conquer idea as counting inversions with merge sort.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 9 (rated M21, recommended): what is it asking?	A neat characterization of involutions using two of the alternative inversion tables from exercise 7. Read 7 first.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 13 (rated M23): what is it asking?	Show that inversion counts are evenly spread modulo m once n is at least m. Generalizes the even/odd split of permutations.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 21 (rated M25, recommended): what is it asking?	Which permutations a stack can produce, described with an inversion-table condition. Ties back to the railway problems in Vol 1.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 28 (rated 25, recommended): what is it asking?	Bound the total distance elements sit from home in terms of the inversion count. Useful intuition for why insertion sort is quadratic.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1, exercise 25 (rated M30, recommended): what is it asking?	Build the Foata bijection that trades the index of a permutation for its inversion count. The stretch; give it a fixed time box.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercise
TAOCP §5.1.1: how many exercises, and how are they rated?	29 exercises, rated 10 to M43.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::exercises
TAOCP §5.1.1: what should you be comfortable with first?	<ul><li>1.2.5 Permutations</li><li>1.2.9 Generating Functions</li><li>1.3.3 Applications to Permutations</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::prereqs
TAOCP §5.1.1: how should you work through it?	Compute inversion tables for several permutations of 1..5 by hand and convert back. Write code for both directions. Then count inversions in O(n log n) with a modified merge sort.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.1.1 cracked.guide::kind::approach
