#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 3::5.2.4 Sorting by Merging
#columns:Front	Back	Tags
TAOCP §5.2.4 Sorting by Merging: what does it cover?	Merging two sorted lists, two-way merge sort on arrays (natural and straight versions), and list merge sort that works on linked records without moving data.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::about
TAOCP §5.2.4: why does it matter?	Merge sort is stable and the basis for Timsort (Python, Java objects) and for external sorting. List merge sort is the right way to sort linked lists.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::why
TAOCP §5.2.4: what traps should you watch for?	<ul><li>Knuth's array merge sorts are bottom-up and alternate between two memory areas; losing track of which area holds the current runs is the usual bug.</li><li>Breaking stability by taking from the right run on ties.</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::traps
TAOCP §5.2.4, exercise 1 (rated 21): what is it asking?	Generalize two-way merging to k-way. The building block of external sorting later in the chapter.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4, exercise 3 (rated 20, recommended): what is it asking?	Merge an update file into a master file, letting new records replace old ones. Classic batch-processing pattern.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4, exercise 5 (rated 21, recommended): what is it asking?	Show that two pointers in the natural merge can never meet in certain steps, so a test can be dropped.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4, exercise 11 (rated 21): what is it asking?	Is list merge sort stable? Check the tie-breaking rule.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4, exercise 12 (rated 22, recommended): what is it asking?	Make list merge sort exploit runs already in the input, so sorted input finishes in one pass.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4, exercise 21 (rated 23): what is it asking?	Count inversions as a side effect of list merge sort. The standard interview problem, from the source.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4, exercise 13 (rated M34, recommended): what is it asking?	Average-case analysis of the list merge sort program. The stretch.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercise
TAOCP §5.2.4: how many exercises, and how are they rated?	23 exercises, rated 16 to 47.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::exercises
TAOCP §5.2.4: what should you be comfortable with first?	<ul><li>5.2.1 to 5.2.3</li></ul>	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::prereqs
TAOCP §5.2.4: how should you work through it?	Implement top-down and bottom-up merge sort on arrays and list merge sort on a linked list. Check stability with records that have equal keys.	cracked.guide cracked.guide::phase::taocp-3 cracked.guide::section::5.2.4 cracked.guide::kind::approach
