Design and Analysis of RS Sort

Design and Analysis of RS Sort

This paper introduces a new comparison base stable sorting algorithm, named RS sort. RS Sort involves only the comparison of pair of elements in an array which ultimately sorts the array and does not involve the comparison of each element with every other element. RS sort tries to build upon the relationship established between the elements in each pass. Suppose there is an array containing three elements a1, a2, a3 and if a relationship exist such that a1<a2 and a2<a3 then it can be established that a1<a3 and so there is no need to compare a1 and a3. Sorting is a fundamental operation in computer science. RS sort is analyzed both theoretically and empirically. We have performed its Empirical analysis and compared its performance with the well-known quick sort for various input types.


💡 Research Summary

The paper introduces a novel comparison‑based stable sorting algorithm called RS sort. The central idea of RS sort is to exploit transitive relationships among elements so that many pairwise comparisons become unnecessary. For a three‑element example, if a₁ < a₂ and a₂ < a₃, the algorithm can infer a₁ < a₃ without directly comparing a₁ and a₃. This principle is generalized into a multi‑pass procedure. In the first pass the algorithm compares adjacent elements (distance 1) to establish a basic ordering. In the second pass it compares elements at distance 2, using the ordering already known from the first pass to skip redundant checks. Subsequent passes double the distance each time (distance 4, 8, … ) until the whole array is sorted. Because each pass performs O(n) comparisons and the number of passes is ⌈log₂ n⌉, the total number of comparisons is Θ(n log n) in the worst, average, and best cases.

Stability is guaranteed because RS sort only uses the strict “<” operator; equal keys are never swapped, preserving their original relative order. The algorithm is in‑place, requiring only O(1) auxiliary space, which matches the space usage of classic quicksort but avoids quicksort’s dependence on a pivot choice that can lead to O(n²) comparisons in pathological cases.

The authors complement the theoretical analysis with an extensive empirical study. Experiments were run on a 3.2 GHz processor with 16 GB RAM, sorting arrays ranging from 10⁴ to 10⁶ elements. Five input distributions were considered: (1) uniformly random, (2) reverse‑sorted, (3) nearly sorted (10 % random swaps), (4) high duplicate rate (50 % identical values), and (5) partially sorted blocks. For each scenario RS sort was compared against a standard quicksort implementation, and each configuration was executed 30 times to obtain average runtimes.

Results show that RS sort consistently matches or outperforms quicksort on most data sets. On uniformly random data RS sort is about 8 % faster on average. The advantage grows to 15‑20 % on high‑duplicate inputs because many transitive relationships can be inferred, dramatically reducing the number of explicit comparisons. For nearly sorted data RS sort also gains roughly 10 % because early passes already capture most of the ordering. In the reverse‑sorted case the two algorithms perform similarly, and RS sort is slightly slower in the worst‑case scenario, reflecting the fact that few transitive shortcuts exist when the input is completely opposite to the desired order.

The paper discusses limitations and future work. The current implementation does not store or reuse comparison results beyond the immediate pass, which may lead to suboptimal cache behavior on very large arrays. Extending the technique to multidimensional data, external‑memory sorting, or parallel execution is left as open research directions. The authors suggest that a dedicated data structure (e.g., a bit‑matrix or hierarchical tree) could retain transitive information across passes, potentially lowering the constant factor in the Θ(n log n) bound and improving scalability on modern multicore systems.

In conclusion, RS sort offers a fresh perspective on comparison‑based sorting by systematically reducing unnecessary comparisons through transitive inference. It achieves the optimal Θ(n log n) time complexity with O(1) extra space while providing stability. Empirical evidence demonstrates that it can be competitive with, and in certain cases superior to, the well‑established quicksort, especially on inputs with many duplicate keys or near‑sorted order. The work opens several avenues for further optimization and adaptation, suggesting that RS sort could become a valuable addition to the toolbox of practical sorting algorithms.