#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 3::5.2.3 Sorting by Selection
#columns:Front	Back	Tags
TAOCP §5.2.3 Sorting by Selection: what does it cover?	Straight selection, tree selection (tournaments), and heapsort with the heap data structure, plus analysis and the use of heaps as priority queues.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::about
TAOCP §5.2.3: why does it matter?	Heaps are the standard priority queue, used in Dijkstra, schedulers and top-k queries. Heapsort is the in-place O(n log n) worst-case fallback in introsort.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::why
TAOCP §5.2.3, fill in the blank:<br>Heapsort is the in-place <span class="cg-blank">&nbsp;</span> worst-case fallback in introsort.	Heapsort is the in-place <b>O(n log n)</b> worst-case fallback in introsort.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::complexity
TAOCP §5.2.3: what traps should you watch for?	<ul><li>Off-by-one in parent and child index formulas, especially 0-based versus Knuth's 1-based arrays.</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::traps
TAOCP §5.2.3, exercise 1 (rated 10): what is it asking?	Is straight selection stable? Think about what a long-distance swap does to equal keys.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 16 (rated 20): what is it asking?	Insert a key into a heap: the sift-up half of every priority queue.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 22 (rated 20, recommended): what is it asking?	Work backward to find which inputs heapify into a given heap. Tests that you really understand sift-down.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 18 (rated 21, recommended): what is it asking?	Floyd's improvement: sift the hole to the bottom first, then back up. Nearly halves the comparisons.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 8 (rated 24, recommended): what is it asking?	Make straight selection remember what it learned on the previous scan, and write it in MIX.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 15 (rated M22, recommended): what is it asking?	Generate primes with a priority queue instead of division. A surprising use of heaps.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 33 (rated 21): what is it asking?	Merge two leftist-tree priority queues. A mergeable heap in a few lines.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3, exercise 4 (rated M25, recommended): what is it asking?	Is testing for a no-op swap worth it in straight selection? Average-case analysis with a practical answer.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercise
TAOCP §5.2.3: how many exercises, and how are they rated?	38 exercises, rated 10 to M41.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::exercises
TAOCP §5.2.3: what should you be comfortable with first?	<ul><li>5.2.2 Sorting by Exchanging</li><li>2.3 Trees</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::prereqs
TAOCP §5.2.3: how should you work through it?	Implement heapsort from scratch with an array-based heap. Then implement a priority queue with insert and delete-min and use it for something real like merging k sorted files.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.3 cracked.guide::kind::approach
