THE AUTOMATED FLOWCHART DESIGN AND CODE WRITING SYSTEM |
Home || Contact us || Create code logic ||xx |
The best In-place optimum stable sort algorithm |
|
BEST IN-PLACE OPTIMUM MERGE ALGORITHMSThis internal merge operation is the fastest internal merge there is! It is used to implement an internal merge-sort that results in the fastest internal stable sort algorithm there is! The merge operation is done in a manner very similar to that of natural merge except that we are using Kronrod's ideas of block partition and the internal buffer. Only this time we are doing it differently from every body else. I use an encoding technique to keep track of Displaced blocks in their original order during "local block merge" in order to maintain stability. I am currently developing a new encoding technique that will simplify and improve the overall merge operation. In fact, I have just realised that this can be used to implement an in-place k-way merge-sort that is optimum on the number of comparisons and that does O(N) data move operations. I will put it in a book and then ask you to purchase a copy if you want to see it! Why should I submit it to a journal? That ungodly system of thievery and self-centred promotion. |
|||||||
A FAR BETTER APPROACH WITH IMPROVE PERFORMANCE |
||
THE NEW MERGE TECHNIQUE 1 |
||
| Page 4 of 6 | |
![]() |
![]() |
ABSTRACT 1
An Optimum In-place Merge Algorithm |
||
|
\begin{abstract} Key Terms: Internal Merge, Stable Merge, Kronrod's technique, Block Rearrangement, Internal Buffer, |
USE OF TERMS |
||
|
\section{The Problem Definition} Our two sorted lists to be merged are located in two arrays denoted as A and B, where |A|=m, |B|=n. Arrays A and B are parts of the larger array L defined as follows:A=L[0:m-1] and B=L[m:m+n-1]. We desire to stable merge A and B in-place using the locations in L as output for the final merge. Ø A current block is a block on which a merge operation is currently taking place. |
||
An Instance Illustration of the New Merge Technique |
||
|
|
||
|
Possible distribution of values in A and B at the end of merging the 2nd block in L
|
||
|
Assume that A1 is the next block with
the smallest mark. The distribution of values in L at the end of
merging the 3rd block is as illustrated below. |
||
|
|
||
Note that except for the last k size block in the A list and the permuted buffer, the values in each list at this stage are sorted. A single block exchange operation brings the buffer into a single k size block whilst at the same time bringing the two undersized merged blocks into a single full block. The buffer is then sorted using an optimum sort algorithm. A stable block sort on L excluding the buffer, creates a single sorted list as desired. |
||
|
|
||
OPERATIONAL COMPLEXITY |
||
|
Number of comparisons for block selection during local block merge is n = n1+n2-1, where n1 is the number of full blocks in A and n2, is the number of full blocks in B. Number of data moves to place each element during local block merge is 3{(n+m)-(k+s+s'+r)} Number of comparisons during block sorting is "n(n-1) if a selection sort is used to sort the blocks. Number of data moves is an additional 3{(n+m)-(k+s+s'+r)} Therefore, total comparisons from these two phases is 3{(n+m)-(k+s+s'+r)}+ n2. Total data moves is 6{(n+m)-(k+r+s+s')}. Note that we can reduce the number of data moves per element from 3 to 2 by using the technique, which explained later on. Therefore, this reduces the total number of data moves to 4{(n+m)-(k+s+s'+r)}. Comparisons and data moves respectively during buffer extraction are as follows (k+s+r) comparisons and no more than 3(k+2s+r) moves. |
||
ABSTRACT 2
Merging with m+n+o(m) comparisons and 2(m+n) +o(m) Moves |
||
|
\begin{abstract} Key Terms: Internal Merge-sort, Sorting, Internal Buffer, Stable Merge, fastest internal merge, best merge algorithm This internal merge operation is the fastest internal merge there is! It is used to implement an internal merge-sort that results in the fastest internal stable sort algorithm there is! The merge operation is done in a manner very similar to that of natural merge except that we are using Kronrod's ideas of block partition and the internal buffer. Operational attributes of the algorithm that distinguishes it from previous algorithms are * Block merge is done concurrently with block selection, to ensure correctness
and simplicity of implementation. |
|
To locate the next A value to be used in the next comparison after an A value has been output we need an algorithm that will find this value, preferable in constant or linear time. There is no algorithm that does this in constant time. An algorithm that does this in linear time uses additional information gathering operation and is generally not stable. Therefore, they add to the computational complexity of the merge operation, they do not select the next value from the permuted list in a stable manner and do not give an overall stable operation. During the merge operation, the displaced list can grow to a maximum of m. The displaced list then swinks back to 0 at the end of the merge operation. If the length of the displaced list is lj at an instance in time, then the linear algorithm will do \fract{1}{2}lj comparisons on average to locate the smallest value in the list. This results from the fact that the displaced values are permuted at random during the merge operation. However, we show further on that this permutation of displaced values is predictable and can therefore be used to develop constant time algorithm to locate the next smallest value from the A list. |
An Instance Illustration of the New Merge Technique |
||
|
|
||
|
Configuration of L at the end of merging the next block in L is as illustrated below.
|
||
|
|
||
|
Roll over counter keeps tract of secondary displace A blocks as follows. If an A block, say Ar was at a displaced location t. If the value of t is less than the roll over counter value, then Ar did not encounter a secondary displacement and is therefore still at its original displaced location. Contrary to this, the new location of Ar is the original location plus the roll over counter value. The original location is obtained from encoded information.
|
||
OPERATIONAL TIME COMPLEXITY |
||
Now reduced to n+m-1 and 3(n+m) comparisons and data moves respectively for merging and no more than 2nlog2(k) and 6n additional comparisons and data moves respectively for block encoding and decoding. Additional Cost due to Buffer extraction · For unstable merge, this is approximately · For stable merge, this is |
||
USING ADDITIONAL CONSTANT MEMORY k |
||
|
In this case, buffer extraction, use and sorting are simplified. However, block encoding becomes more complex. No need for complex buffer extraction and replacement to achieve overall stability of the merge operation. Only need 2 data move operations to merge each element. Number of comparisons remain the same except for block location encoding and decoding operations during the local block merge. New Block Encoding Technique Because in this case, the value of k is a constant independent of the values m and n, there may be more displaced A blocks to be encoded than there are elements in a block to implement this encoding. However, we note that the following invariant properties. What about the encoding technique where there are sequence of equal values in a list and the sequence is greater than the block size. Ans: There is an invariant property tha takes care of this situation quite easily. Can you figure this out? To decode the location of t, do a binary search on the block boundaries using ër/kû as the first lower boundary. |
||
|
||
COMPLEXITY ANALYSIS
We leave this to the reader as a useful exercise.
ABSTRACT 3
Using K-Way Merge to do Optimum Sort With O(N) Moves |
||
| \begin{abstract} We show that for optimum k-way merge of k pre-sorted lists, each consisting of m data values the number of comparisons is n\log2(k)-(k-1), n=km and the number of data moves is n with O(n) additional memory. We use the principles of (1) Block partitioning, (2) Data Encoding, (3) the Encoded Binary Selection Tree and (4) the Internal Buffer to develop an optimum algorithm that merges k pre-sorted lists in-place. For block size \nu=\sqrt{m}, our algorithm does no more than {(n-k-2)+\nu(2k-1)}\log2(k)+{(\nu(k-1)-k}\log2(\nu)+k-2 comparisons and 4n+8(k(\nu-1)-\nu) moves. We use our basic $k$-way merge to implement an in-place merge-sort of $N$ values with the use of no more than N\log2(N)-N\lambda+N{\frac{\lambda}{k}+1+log2(k)}+O(log2(N)) comparisons and 2N(\lambda+4) data moves. Where \lambda=log2(N)/log2(k). We use additional constant memory to reduce the number of data moves to no more than 2N(\lambda+2). By setting k=N{\epsilon}, where 0<\epsilon <1, we improve the number of data moves to no more than 6N\epsilon+o(N) moves while maintaining about the same number of comparisons. We consider our results to be the best for optimum comparisons and O(N) data moves so far to those given in the literature. \End{abstract} Key Terms: Bit, Binary selection tree, Block partition, Internal buffer, Internal merge, k-way merge, In-place and stable merge, Operational complexity analysis. |
||
New Block Encoding Technique
Click NEXT button for Information about sorting in 2-dimension
| Page 4 of 6 | |
![]() |
![]() |