Abstract

Merge sort is one of the asymptotically optimal sorting algorithms that is used in many places including programming language library functions and operating systems. In this paper, we give a modified version of merge sort, which in practice shows substantial improvement in running time than the top-down and bottom-up implementations of the classical merge sort. Our algorithm works as a bottom-up manner and the modifications happen in three places: (a) given n elements in an array, first the algorithm considers the array as n / 2 consecutive pairs and sorts each pair in-place by one comparison; (b) in subsequent steps, during the ”merge” process of two subarrays, if the last element in the left subarray is smaller than the first element in the right subarray, the algorithm simply returns; and (c) if the last element in the right subarray is smaller than the first element in the left subarray, then the algorithm swaps the elements in the two subarrays by their entirety. Steps (b) and (c) happen in-place. For the case not in (b) or (c), the algorithm follows the classical merge technique with an extra array. Our experimental results also show that case (b) and (c) happen a good amount of time in practice and that is the reason that our algorithm gives better running time than the classical merge sort.

Highlights

  • Merge sort is a comparison-based sorting algorithm

  • enhanced merge sort algorithm (EMS) saves the execution time compared to the regular merge sort in both the number of comparisons and the number of copies performed among the elements

  • We have implemented in Java EMS as well as the classical merge sort algorithm in topdown and bottom-up manner

Read more

Summary

Introduction

Merge sort is a comparison-based sorting algorithm. It has asymptotically optimal running time of O(n log n) in worst case and average case. EMS shows substantial improvement in running time than the top-down and the bottomup implementations of the classical merge sort. EMS sorts by one comparison each pair of elements (A[i], A[i + 1]), for i = 0, 2, 4, . For the remaining rounds from 1 to log n − 1, the algorithm sorts pairs of consecutive subarrays individually, one after another from left to right, according to the following three cases.

Results
Conclusion
Full Text
Published version (Free)

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