Best Sorting Algorithm For Nearly Sorted Lists
Best Sorting Algorithm For Nearly Sorted Lists
THE STUDY
While defining the best sorting algorithm it can be said that:
The one whose weighted sum of the number of comparisons,
moves, and exchanges (where an exchange is equal to two
comparisons or two moves) is minimal is the most efficient
algorithm.
While taking an assumption that a comparison is a binary
comparison, and a move is typically a transfer from a word in
memory to a register or vice versa, and an exchange is the
interchange of the contents of two words in memory.
Furthermore, coming to the idea of a nearly sorted list we can say that
a list is nearly sorted if only a few of its elements are out of order. The
problem is to define an easily computed measure that coincides with
intuition.
2
After taking the above regulations under consideration the New
Algorithm that was produced as a result is stated below:
First the original list is scanned and pairs of unordered elements
are removed and placed in another array.
After a pair of unordered elements has been removed, the next
pair compared are the elements immediately preceding and
immediately following the pair just removed.
After repeating this for all of the elements in the original list, the
array of unordered pairs of elements are sorted by Straight
Insertion if there are no more than 30 elements and by Quicker
-sort otherwise.
Finally, the two sorted arrays are merged into one array.
THE INFERENCE
The results of the experiment have been tabulated for a particular set of
values that have been treated to the other five algorithms that were taken
into consideration. The following table (Table-I) presents a comparative
study of these algorithms to give the readers a better idea into the
performance (measure of sorted-ness) of the algorithms under
inspection.
3
Now When the experiment was performed for the same values using the
New sorting algorithm the following performance results were obtained
(As tabulated in Table-II)
THE CONCLUSION
The values in Table II show that the New Sorting Algorithm compares
favorably with the Straight Insertion Sort for small and very nearly
4
sorted lists and some values are one-half of the value for many of
those for the corresponding Quicker-sort.
The New Sorting Algorithm appears to take more advantage of the
sorted-ness of the list than either Straight Insertion or Quicker sort.
Also, note that in the worst case the New Sorting Algorithm reduces
to Quicker-sort, plus the size of the list number of moves for merging.
The New Sorting Algorithm also suggests that other new and faster
sorting algorithms for nearly sorted lists may be developed from
methodical combinations of sorting algorithms.
However the investigation conducted by the authors is not complete
and warrants further inspection and evaluation in terms of other
criteria that define the effectiveness of a sorting algorithm. But it can
be concluded that: taking the number of comparisons into perspective
the new sorting algorithm performs way better than the Other ones
considered in this study.
REFERENCES