apr23.txt ------------------------ Endgame: HW9 difficulty predictions due (to me) by Thursday midnight Optional problem session sometime Sunday afternoon, 2 p.m., CSB 632 Final required session on Tuesday, as scheduled, including course evaluation No final quiz HW9 grand finale, due by end of classes: CLR: 30-1(c), 30-2(c) CLRS: 27.1-2, 3, 7, 8 27.2-5 27.3-3 27.4-3, 4, 5 27.5-5 27-1 (*and* 27.1-6) 27-2 284 exemptions: Any 3 of the 15 ------------------------ Omitted last time: ``The zero-one principle'' Underlying observation (Lemma 27.1), stated less formally: If you replace the elements of any input sequence to a comparison network, in a way that ``preserves order'' (even in just the <= sense), then the network will perform a permutation that is indistinguishable from the original one. Proof: Consider side-by-side executions, inductively. Each successive comparator both performs its same action (except in case of tie, in which case its action does not matter) and preserves the relationship between the orderings. Corollary ((contrapositive of) Zero-One Principle): If a comparison network *mis*sorts some input sequence, then it missorts some *binary* input sequence (obtainable by an order-preserving map). Proof: Look at a missorted sequence, and focus on a first deviation from sorted order; i.e., look at the minimum i such that all instances of the i smallest elements don't end up first in the output. Replace all instances of the i smallest elements by 0's and the rest by 1's, to get a missorted binary sequence. Sample application (of the parenthesized afterthought, actually): Reprove correctness of Batcher's odd-even merger (more easily?): Enough to show correct merging of sorted binary sequences. (See relevance of the afterthought?) Calculate the 0 contributions to the respective subproblems: >From first input list: i odd and either i or i-1 even positions. >From second input list: j odd and either j or j-1 even positions. Totals: i+j in first subproblem (odds) and either i+j, i+j-1, or i+j-2 in second subproblem (evens). In the first 2 of the 3 cases, the odds-first shuffle does fine. Third case: Shuffle yields 00...00010111...11, where the isolated 1 is from the second subproblem, hence fixable by an even-odd switch.