A New Optimized Version of Merge Sort
A New Optimized Version of Merge Sort
2023 11th International Conference on Emerging Trends in Engineering & Technology - Signal and Information Processing (ICETET - SIP) | 979-8-3503-4842-2/23/$31.00 ©2023 IEEE | DOI: 10.1109/ICETET-SIP58143.2023.10151579
Abstract-The ordering of items of an array/list in all around the world and is seen as a necessary task.
a certain sequence is one of the crucial topics in In daily life, the most significant sorting application
computer science. Sorting algorithms determines the is utilised. For example: Phone book faster access to
new order of elements in a data structure typically in contacts, income tax files, contents of tables,
arrays and lists, they do so based on a comparison libraries access, dictionaries, search engine [6].
operator. The effectiveness of these sorting algorithms
is determined by calculating their time and space
complexity. Financial institutions and commercial
enterprises organize much of the information by
sorting. They must deal with a large amount of data.
There might be millions of data rows. Now we have
enough space but less time that is also one the major
reasons of microservices architecture is being used
nowadays. The microservice design enables the fast,
frequent, and reliable delivery of large, sophisticated
applications. Hence, the algorithms must be lightning
fast. The purpose of this study is to improve on the
classic Merge Sort Algorithm and create a new
approach with a faster execution time. Merge sort is a
popular method for sorting large datasets since it is
typically efficient and straightforward to implement.
The proposed method surpasses the standard Merge Fig.1. A useful Big-O Complexity Graph to visualize how the
Sort algorithm, which has a time complexity of O(nlog2 number of operations and time grow as number of elements
n). The proposed approach has been examined, increases.
executed, and compared, with favourable findings and
the suggested modified mergesort algorithm is 12.12%
faster than the usual merge sort. II. PROPOSED ALGO
Keywords- Divide and Conquer; External Sorting; Merge Sort, one of the Divide and Conquer
stack; Recursive; Merge Sort sorting algorithms, has a wide range of applications.
In the case of big arrays, this sorting method has a
I. INTRODUCTION temporal complexity of O(nlog2n) and can
outperform the Insertion sort [7].When the array or
The organisation of items in a specified sequence list is a reverse order list ,it is more fast even more
has always been one of the key and fundamental than Quick sort [8].
challenges of computer science. These issues are
addressed by a variety of sorting algorithms. Some A. Merge Sort Working Process:
of these algorithms are simple and spontaneous, like Consider it a recursive procedure that splits the
Insertion Sort while others are extremely complex, array into two half repeatedly until it can no longer
like Quick Sort yet provide quick results [1], [2]. be divided further. This means that splitting will stop
Almost all sorting algorithms are problem specific if the array becomes empty or has just one element
[3]. While some algorithms do well with tiny data, left, which is the base conditions and the reason for
some perform well with vast data. While some can the recursion to finish as a single element is already
handle lists with repeated values, some are better sorted. If the array has multiple elements, divide it
suited to floating point values. We usually sort the in half and recursively apply the merge sort on each
lists in statistical order or in lexicographical order, half. After sorting both portions, the merging
in ascending or descending order [4], [5]. In their process is used. The merge technique combines two
own fields of programming, many software smaller sorted arrays into a bigger sorted array. The
engineers rely on various sorting algorithms, such as Divide and Conquer concept serves as the
Merge, Fast sort, etc. Sorting is a common practise foundation for the proposed sorting method
Authorized licensed use limited to: PONTIFICIA UNIVERSIDADE CATOLICA DO RIO DE JANEIRO. Downloaded on April 03,2024 at 23:27:20 UTC from IEEE Xplore. Restrictions apply.
(2.C) numsary [1] = temp; • The number of items is denoted by n.
3. if (numsary [2] < numsary [1]) • Because we continually split the sub-arrays
(3.A) temp = numsary [1]; into two equally sized pieces, doubling the
(3.B) numsary [1] = numsary [2]; amount of items n requires just one more
(3.C) numsary [2] = temp; step of divisions d. The fig.3 below shows
(3.D) if (numsary [1] < numsary [0]) that four items require two division steps,
(i)temp = numsary [0]; while eight elements require only one more
(ii) numsary [0] = numsary [1]; step. Thus the number of division stages is
(iii) numsary [1] = temp; log2 n.
(2.B) else
(i)array[k++]= right_ary [j++] Fig.3. Divisions in merge sort
Authorized licensed use limited to: PONTIFICIA UNIVERSIDADE CATOLICA DO RIO DE JANEIRO. Downloaded on April 03,2024 at 23:27:20 UTC from IEEE Xplore. Restrictions apply.
TABLE I. Time taken to sort elements between MergeSort and
Proposed Algo
NUMBER OF TIME(ms) BY TIME(ms) BY
ELEMENTS MERGE PROPOSED
SORT ALGO
1K 0 0
10K 3 2
100K 46 24
1000K 234 167
10000K 1768 1592
50000K 9533 8695
70000K 15024 13040
Fig.4. Recursive tree for the proposed algorithm. 90000K 19307 17065
100000K 21347 18524
VI. SPACE COMPLEXITY The above table have been plotted in graphs as
shown in Fig. 5 and Fig.6.
The function MERGE_SORT(int[] nums) of the
proposed algorithm Divide the array into two parts
the left part and the right part. we store left part and
right part in temporary(auxiliary) arrays and then
280
use original array to store the completely merged
array. Thus, In proposed algorithm all elements are 245
copied into an auxiliary array so O(N) auxiliary
Execution Time( ms)
210
space is required for proposed algorithm. Where N
is the total number of elements. 175
140
105
VII. COMPARATIVE EXECUTION 70
ANALYSIS AND ALGORTIHM
BENCHMARKING 35
0
The time that passes between the beginning and 1K 10K 100K 1000K
finish of an event is generally referred to as the
elapsed time. These are two methods for finding Number of Elements(n)
elapsed time in Java. The current time is given via TIME BY MERGE SORT
the currentTimeMillis() method in milliseconds. The TIME BY PROPOSED ALGO
current time in nanoseconds is returned by the
Fig.5. Comparative execution times of MergeSort and Proposed
nanoTime() method [9].We may calculate the
algorithms.
amount of time that has passed since the execution
of a method by comparing the time values before and
after it. In our paper we used currentTimeMillis() 24000
Execution Time( ms)
21600
method to find the execution in milliseconds. The 19200
suggested algorithm's execution times have been 16800
14400
determined for various values of n. (number of array 12000
9600
elements).These execution times are compared to 7200
the execution times of standard Mergesort for 4800
2400
various values of n (number of array elements). 0
10000K 50000K 70000K 90000K 100000K
The Table 1 shows the comparison between the Number of Elements(n)
time taken in sorting randomly generated elements
between the proposed algorithm and the
TIME BY MERGE SORT
conventional merge sort algorithm.
TIME BY PROPOSED ALGO
Fig.6. Comparative execution times of MergeSort and Proposed
algorithms
Authorized licensed use limited to: PONTIFICIA UNIVERSIDADE CATOLICA DO RIO DE JANEIRO. Downloaded on April 03,2024 at 23:27:20 UTC from IEEE Xplore. Restrictions apply.
TABLE II. Time taken to sort elements between Standard MergeSort and Proposed Algo and Percentage Improvements
1K 0 0 0 0
10K 3 2 1 33.33333333
100K 46 24 22 47.82608696
1000K 234 167 67 28.63247863
10000K 1768 1592 176 9.954751131
50000K 9533 8695 838 8.790517151
70000K 15024 13040 1984 13.20553781
90000K 19307 17065 2242 11.61236857
100000K 21347 18524 2823 13.22434066
Total 67262 59109 8153 12.12125717
According to the graph above in Fig.5 and shortcoming of the traditional Merge Sort approach.
Fig.6 , when n=1000, both Conventional Merge Sort It still needs auxiliary space of O(n). In the future,
and the suggested modified mergesort require we will endeavour to solve such a situation.
almost the same amount of time to run. As n grows,
the execution time of Merge Sort exceeds the
execution time of the suggested Algorithm. Which x. REFERENCES
indicates that proposed algorithm is fast than the
conventional merge sort. The above Table II. shows
the detailed comparison and the percentage [1] I. T. Adamson, "Sorting," in Data structures and
performance improvement. We can see from the algorithms A First Course, Springer, 2012, pp. 79-85.
Table II. that There has been an average [2] A. A. S. S. A. S. C. Pira, "“Doubly Inserted Sort: A
improvement of about 12.12 per cent is achieved. Partially Insertion Based Dual Scanned Sorting
Algorithm”," in Emerging Research in Computing,
Thus, the suggested modified merge sort algorithm
Information, Communication and Applications
is about 12.12% quicker than the usual merge sort. (ERCICA), 2015.
[3] D. M. D. a. P. S. Y. J. L. Wolf, "A Parallel Sort Merge
VIII. CONCLUSION Join Algorithm for Managing Data Skew," IEEE
Transactions on Parallel and Distributed Systems, vol. 4,
The time complexity of both the standard and pp. 70-86, 1993.
suggested techniques is O(nlog2n).The proposed [4] D. Knuth, "Sorting and Searching," in The Art of
algorithm runs faster than the conventional merge Computer programming Sorting and Searching,
sort. The proposed algorithm prevents recursive Addison- Wesley,, 1998.
calls on arrays of size 3 and 2 by putting elements of [5] R. E. Neapolitan, Foundations of Algorithms (Fifth
arrays of size 3 and 2 in the correct order in constant Edition), Jones & Bartlett Learning, 2015.
time. This modification in the base case of [6] M. P. C. a. M. J. S. Somani, "Comparative Analysis &
conventional merge sort results a new modified Performance of Different Sorting Algorithm in Data
version of the mergesort which is about 12.12% Structure," International Journal of Advanced Research
in Computer Science and Software Engineering, vol. 3,
faster than the conventional one.
no. 11, pp. 500-507, 2013.
Due to the prevalence of Merge Sort in file
[7] "www.ijarcsse.com/docs/papers/Volume_3/3_March201
storage and databases, a modified version of the 3/V3I3-0319.pdf," ijarcsse, March 2013. [Online].
method requires less work from the programmer in
[8] K. W. Robert Sedgewick, "Algorithms, Part I,"
order to provide quick access to an item. Cousera,Princeton University, 2022.
[9] Oracle JAVA Docs, "JAVA 10 lang Systems," Oracle,
IX. FUTURE SCOPE 2022. [Online]. Available:
https://docs.oracle.com/javase/10/docs/api/java/lang/Sys
Although the suggested technique sorts a large tem.html. [Accessed 1 2023].
list of elements in less amount of time as compared
to standard Divide and Conquer MergeSort
algorithm, it cannot eliminate the primary
Authorized licensed use limited to: PONTIFICIA UNIVERSIDADE CATOLICA DO RIO DE JANEIRO. Downloaded on April 03,2024 at 23:27:20 UTC from IEEE Xplore. Restrictions apply.