Algorithms and Data Structures
Algorithms and Data Structures
Algorithms and Data Structures
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
N.Wirth. <strong>Algorithms</strong> <strong>and</strong> <strong>Data</strong> <strong>Structures</strong>. Oberon version 98<br />
from both ends inward; compare its performance with that of the procedure given in this text.<br />
2.11. Note that in a (two-way) natural merge we do not blindly select the least value among the available<br />
keys. Instead, upon encountering the end of a run, the tail of the other run is simply copied onto the output<br />
sequence. For example, merging of<br />
2, 4, 5, 1, 2, ...<br />
3, 6, 8, 9, 7, ...<br />
results in the sequence<br />
2, 3, 4, 5, 6, 8, 9, 1, 2, ...<br />
instead of<br />
2, 3, 4, 5, 1, 2, 6, 8, 9, ...<br />
which seems to be better ordered. What is the reason for this strategy?<br />
2.12. A sorting method similar to the Polyphase is the so-called Cascade merge sort [2.1 <strong>and</strong> 2.9]. It<br />
uses a different merge pattern. Given, for instance, six sequences T0 ... T5, the cascade merge, also<br />
starting with a "perfect distribution" of runs on T0 ... T4, performs a five-way merge from T0 ... T4 onto<br />
T5 until T4 is empty, then (without involving T5) a four-way merge onto T4, then a three-way merge onto<br />
T3, a two-way merge onto T2, <strong>and</strong> finally a copy operation from T0 onto T1. The next pass operates in<br />
the same way starting with a five-way merge to T0, <strong>and</strong> so on. Although this scheme seems to be inferior<br />
to Polyphase because at times it chooses to leave some sequences idle, <strong>and</strong> because it involves simple<br />
copy operations, it surprisingly is superior to Polyphase for (very) large files <strong>and</strong> for six or more sequences.<br />
Write a well structured program for the Cascade merge principle.<br />
References<br />
[2.1] B. K. Betz <strong>and</strong> Carter. Proc. ACM National Conf. 14, (1959), Paper 14.<br />
[2.2] R.W. Floyd. Treesort (<strong>Algorithms</strong> 113 <strong>and</strong> 243). Comm. ACM, 5, No. 8, (1962), 434, <strong>and</strong><br />
Comm. ACM, 7, No. 12 (1964), 701.<br />
[2.3] R.L. Gilstad. Polyphase Merge Sorting - An Advanced Technique. Proc. AFIPS Eastern Jt.<br />
Comp. Conf., 18, (1960), 143-48.<br />
[2.4] C.A.R. Hoare. Proof of a Program: FIND. Comm. ACM, 13, No. 1, (1970), 39-45.<br />
[2.5] C.A.R. Hoare. Proof of a Recursive Program: Quicksort. Comp. J., 14, No. 4 (1971), 391-95.<br />
[2.6] C.A.R. Hoare. Quicksort. Comp.J., 5. No.1 (1962), 10-15.<br />
[2.7] D.E. Knuth. The Art of Computer Programming. Vol. 3. Reading, Mass.: Addison- Wesley, 1973.<br />
[2.8] H. Lorin. A Guided Bibliography to Sorting. IBM Syst. J., 10, No. 3 (1971), 244-254.<br />
[2.9] D.L. Shell. A Highspeed Sorting Procedure. Comm. ACM, 2, No. 7 (1959), 30-32.<br />
[2.10] R.C. Singleton. An Efficient Algorithm for Sorting with Minimal Storage (Algorithm 347). Comm.<br />
ACM, 12, No. 3 (1969), 185.<br />
[2.11] M.H. Van Emden. Increasing the Efficiency of Quicksort (Algorithm 402). Comm. ACM, 13, No.<br />
9 (1970), 563-66, 693.<br />
[2.12] J.W.J. Williams. Heapsort (Algorithm 232) Comm. ACM, 7, No. 6 (1964), 347-48.