#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 3::5.2.1 Sorting by Insertion
#columns:Front	Back	Tags
TAOCP §5.2.1 Sorting by Insertion: what does it cover?	Straight insertion, binary insertion, Shellsort with diminishing increments, list insertion, and address-calculation sorting, each with careful analysis.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::about
TAOCP §5.2.1: why does it matter?	Insertion sort is what fast library sorts use for small subarrays. Shellsort is still a practical choice in embedded code with no recursion.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::why
TAOCP §5.2.1, fill in the blank:<br>Using binary insertion and expecting big wins on arrays: moves still cost <span class="cg-blank">&nbsp;</span>.	Using binary insertion and expecting big wins on arrays: moves still cost <b>O(n^2)</b>.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::complexity
TAOCP §5.2.1, a common trap: “Shellsort performance depends hugely on the increment sequence.” What's the catch?	Do not use powers of two.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::trap
TAOCP §5.2.1: what traps should you watch for?	<ul><li>Using binary insertion and expecting big wins on arrays: moves still cost O(n^2).</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::traps
TAOCP §5.2.1, exercise 1 (rated 10): what is it asking?	Is straight insertion stable? One-line answer, but say why.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 4 (rated M20, recommended): what is it asking?	Best and worst running time of the MIX straight insertion program. Ties the code to the inversion count.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 13 (rated M16, recommended): what is it asking?	Put the inversion-counting weights on the other edges of the lattice path. Quick, and it makes the picture click.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 10 (rated 22, recommended): what is it asking?	Skip shellsort's wasted work when an element is already in place, and judge whether it pays off.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 25 (rated M22, recommended): what is it asking?	Count permutations that are both 2-ordered and 3-ordered. The fact behind fast shellsort increment sequences.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 33 (rated 25, recommended): what is it asking?	Speed up list insertion with a sentinel so the inner loop does less work. A classic micro-optimization.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 31 (rated 25, recommended): what is it asking?	Write Pratt's shellsort (increments of the form 2^p 3^q) in MIX and express its running time.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1, exercise 5 (rated M27, recommended): what is it asking?	Full probability distribution of straight insertion's running time. The stretch.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercise
TAOCP §5.2.1: how many exercises, and how are they rated?	44 exercises, rated 10 to HM43.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::exercises
TAOCP §5.2.1: what should you be comfortable with first?	<ul><li>5.1.1 Inversions</li><li>1.2.10 Analysis of an Algorithm</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::prereqs
TAOCP §5.2.1: how should you work through it?	Implement straight insertion and Shellsort with a few increment sequences. Count comparisons and moves on random data and compare with Knuth's formulas and tables.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.1 cracked.guide::kind::approach
