Abstract

We present two algorithms that are near optimal with respect to the number of inversions present in the input. One of the algorithms is a variation of insertion sort, and the other is a variation of merge sort. The number of comparisons performed by our algorithms, on an input sequence of length n that has I inversions, is at most $$n\,{\rm log}_{2} (\frac{I}{n} + 1) + O(n)$$. Moreover, both algorithms have implementations that run in time $$O(n\,{\rm log}_{2} (\frac{I}{n} + 1)\,+\,n)$$. All previously published algorithms require at least $$cn\,{\rm log}_{2} (\frac{I}{n} + 1)$$ comparisons for some c > 1.

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.