ArticlePDF Available

Abstract and Figures

The aim of this study is to present a stable and adaptable Merge Sort algorithm that uses the design patterns to reduce computational complexity of swaps and memory usage. The order of Settlement of elements recorded by design patterns and merging one element by another (first phase) replaced with chunk merging. This algorithm has been implemented by C++ programming language.
Content may be subject to copyright.
Procedia Computer Science 00 (2010) 000–000
Procedia
Computer
Science
www.elsevier.com/locate/procedia
WCIT-2010
Heuristic and pattern based Merge Sort
Manouchehr Zadahmad jafarloua*,Parisa Yousefzadeh farda
aDep. of Computer, Islamic Azad University-Ilkhchi Branch, Imam St., Ilkhchi, Iran
Abstract
The aim of this study is to present a stable and adaptable Merge Sort algorithm that uses the design patterns to reduce
computational complexity of swaps and memory usage. The order of Settlement of elements recorded by design patterns and
merging one element by another (first phase) replaced with chunk merging. This algorithm has been implemented by C++
programming langua ge.
Keywords: Merge s ort, De sign patt erns, co mputati onal co mplexit y;
1. Introduction
Although many consider that sorting algorithm is a solved problem, useful new sorting algorithms are still being
invented (for example, library sort was first published in 2004). Sorting algorithms are prevalent in introductory
computer science classes, where the abundan ce of algorithms for the problem provides a gentle introduction to a
variety of core algorithm concepts, such as big O notation, divide and conquer algorithms, data structures,
randomized algorithms, best, worst and average case analysis, time-space tradeoffs, and lower bounds.
Classification
Sorting algorithms used in computer science are often classified by([2,3,4]):
xComputational complexity
xComputational complexity of swaps (for "in place" algorithms).
xMemory usage
xRecursion.
xStability: stable sorting algorithms maintain the relative order of records with equal keys (i.e., values). See
below for more information.
xWhether or not they are a comparison sort. A comparison sort examines the data only by comparing two
elements with a comparison operator.
xGeneral method: insertion, exchange, selection, merging, etc..
xAdaptabil ity: Wheth er or not the presortedness of the input affects the running time.
* Manouchehr Zadahmad jafarlou. Tel.: +98-914-407-9505; fax: +98-412-332-6063.
E-mail address: zadahmad@gmail.com
c
2010 Published by Elsevier Ltd. Selection and/or peer-review under responsibility of the Guest Editor.
Procedia Computer Science 3 (2011) 322–324
www.elsevier.com/locate/procedia
1877-0509 c
2010 Published by Elsevier Ltd.
doi:10.1016/j.procs.2010.12.055
Manouchehr Zadahmad jafarlou / Procedia Computer Science 00 (2010) 000–000
2. stgEx pattern, status data structure, stgMerge algorithm and stgMerge sort
stgEx pattern is a Strategy pattern [1] based explorer pattern and has three state (three different algorithm)( Fig.
1) . stgEx explore interior of under sort array. The result of each of algorithms is the data structures called status.
The resulted status array of each algorithm differs in sizes, values and special viewpoin ts of presortedn ess with
another one but all of them can optimize Merge sort algorithm. We call Merge algorithm the stgM and Merge sort
[5,6] the stgMS, because t hese algorithms have three states and implemented with strategy pattern.
Fig. 1. Heuristic and pattern based Merge Sort implementation
2.1. First algorithm
In the first sate, before every calling merge algorithm (stgM), the first state of stgEx pattern called and th e next
partial array in under sorting array has found. This algorithm is a for loop with O(n) time order and produce a tow
element array named status. First element of status is the index of first element of next partial array and the second
one represent "the number of elements of partial array"*(+1) for ascending partial array or *(-1) for descending
partial array.
For example for array -4, -3, 0, 1, 3, 8, 9, 14, 5, 6, 8, 14, 2, 1, -3, 1 … if the (-4, -3, 0, 1, 3, 8, 9, 14) be the part of
array that sorted before with stMS, (5, 6, 8, 14) will be the next partial ordered array and so the status array is (8,
+4)- The result of stgEx. Then stgM called with values of status array (stgM(8, +4)) and then 0->7 indexed partial
sorted array merged with 8->11 indexed new partial array and 0->11 indexed partial sorted array produced with
stgMS algorithm. For the next iteration of stgMS, 0->11 indexed partial sorted array merged with (2, 1, -3)
descending partial array -(stgM(12, -3))- from the last element to the first element to produce an ascending sorted
array and so on.
This algorithm used when the numbers of arrays are so many that cannot move to volatile memory.
2.2. Second algorithm
The second algorithm of stgEx pattern did for whole under sort array. The result (status) is: "the first index of
first entry of partial arrays" * +1 for ascending arrays and "the first index of first entry of partial arrays" * -1 for
descending arrays (O(n)). For example for array -8, -4, 0, 4, 3, 1, 0, -2, 5, 7, 9, 10, 5, 4, 2, 1, 3 status will be +1, -4,
+8, -12, +15 so partial arrays are indexed 0->3 (ascending), 4->7 (descending), 8->11 (ascending), 12->14
(descending), 15->15 (ascending). Then status send as argument to stgMS and partial arrays will be the building
blocks for stgM algorithm.
The second algorithm causes a high performance by eliminating of first steps of merge sort algorithm.
2.3. Third algorithm
M.Z. Jafarlou, P.Y. Fard / Procedia Computer Science 3 (2011) 322–324 323
Manouchehr Zadahmad jafarlou / Procedia Computer Science 00 (2010) 000–000
The third algorithm of stgEx pattern did for whole under sort array. The result (status) is: " the number of partial
arrays " * +1 for ascending arrays and "the number of partial arrays" * -1 for descending arrays (O(n)). For example
for array -8, -4, 0, 4, 3, 1, 0, -2, 5, 7, 9, 10, 5, 4, 2, 1, 3 status will be +3, -5, +4, -4, +1. Then status send as argument
to stgMS and partial arrays will be the building blocks for stgM algorithm.
In this algorithm, stgMS is a Huffman coding algorithm [7,8,9] that optimizes merging process by choosing two
partial arrays th at sum of elements of them is less than others before each merging. Th en these two partial arrays
send as argument to stgM algorithm and merged.
Conclusion
Merge sort is an appropriate algorithm with O(n) Computational complexity, but petitioning of array to one
element partial arrays and then merging them cause increasing complexity in time order, system software and
hardware work. The presented algorithm eliminates these extra work using patterns.
References
1. E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns: Elements of Reusable Object-Oriented
Software, Addison-Wesley, 1995.
2. Bradford, Phillip G.; Rawlins, Gregory J. E.; Shannon, Gregory E. (1998). "Efficient Matrix Chain Ordering in
Polylog Time". SIAM Journal on Computing (Philadelphia: Society for Industrial and Applied Mathematics) 27 (2):
466–490. doi:10.1137/S0097539794270698. ISSN 1095-7111
3. Papadimitriou, Christos H. (1994). Computational complexity. Reading, Mass.: Addison-Wesley. ISBN 0-201-
53082-1.
4. Grötschel, Martin; László Lovász, Alexander Schrijver (1988). "Complexity, Oracles, and Numerical
Computation". Geometric Algorithms and Combinatorial Optimization. Springer. ISBN 038713624X.
5. Cormen, Thomas H.; Leiserson, Charles E., Rivest, Ronald L., Stein, Clifford (2001) [1990]. "2.3: Designing
algorithms". Introduction to Algorithms (2nd ed.). MIT Press and McGraw-Hill. pp. pp. 27–37. ISBN 0-262-03293-
7.
6. Han, Y. and Thorup, M. 2002. Integer Sorting in Expected Time and Linear Space.
In Proceedings of the 43rd Symposium on Foundations of Computer Science (November 16–19, 2002). FOCS.
IEEE Computer Society, Washington, DC, 135-144.
7. D.A. Huffman, "A Method for the Construction of Minimum-Redundancy Codes", Proceedings of the I.R.E.,
September 1952, pp 1098–1102
8. Background story: Profile: David A. Huffman, Scientific American, September 1991, pp. 54–58
9. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms,
Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 16.3, pp. 385–392.
324 M.Z. Jafarlou, P.Y. Fard / Procedia Computer Science 3 (2011) 322–324
... The above procedure is repeated with larger number of elements through the so called conquer steps until it merges two n/2 sized sorted lists into a sorted list of n elements. Several approaches has been proposed to improve the performance of the merge sort algorithm such as top down merge sort [8], natural merge sort [10], queue merge sort [9], in place merge sort [6], bottom up merge sort [11], heuristic merge sort [12], etc. Top-Down merge sort [8], uses a technique to cut the auxiliary array down to half. However no significant effort has been made to reduce the recursive merge function calls which may increase the execution time. ...
... However, the elimination of recursive function calls may increase the sorting time because in this it actually works as worst case merge sort algorithm comparing each and every number with the other number . Heuristic Merge Sort [12], algorithm searches a specific pattern(consecutive ascending or descending numbers) of numbers in the given list of numbers. It extracts sub lists of sorted data, and then uses the merge procedure to merge all the extracted sub lists. ...
... The design pattern reduces computational complexity of swapping operation and memory usage. We have also combined the various approaches which were used in heuristic merge sort [12] and bottom up merge sort [11], to form the merge sort procedure a more efficient one. We have reduced the necessity of dividing the list or the step of splitting (until a single element) and thereby shown an improvement in running time requiring less number of recursive calls to the divide and conquer procedure. ...
Article
Full-text available
Sorting is the arrangement of records or elements in some mathematical or logical order. Merge sort is one among many sorting techniques. Several improvements on the merge sort procedure are done by different researchers that require less space for auxiliary memory and less number of conditions checking. In this paper, a new merge-sort technique is proposed which uses the design patterns to reduce computational complexity of swapping operation and memory usage. The order of settlement of elements is recorded by various design patterns and then merging of one phase of elements with another is replaced with chunk merging. The proposed technique uses the design patterns to create a memory pool of data to sort data. This algorithm has been implemented in JAVA and it is observed that the proposed algorithm performs better than all existing merge sort algorithms. Keywords We would like to encourage you to list 4 to 5 keywords in this section.
... There are several variations of merge sort (Knuth, 1998), (Abhyankar, 2011), (Mergen, 2017), (Kim, 2007), (Buss, 2019), (Kim, 2008), (Kim, 2006), (Kim, 2004), (Katajainen, 1996), (Jafarlou, 2011), (Paira, 2016), (Katajainen, 1997) including several implementations (Katajainen, 1997). Two basic implementations of merge sort are topdown and bottom-up. ...
Article
Full-text available
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.
... The opposite holds for quick sort and binary search [5]. In [10][11][12][13] an implementation and design method for pattern presented and applied that use patterns combination to modeling system and transformation between different models of MDA. Quantitative and qualitative evaluations of it illustrate the ease of reuse, accurate automation, and large granular transformation among modeling levels of MDA. ...
Article
Full-text available
The advancement of processors, parallel processing and wireless networking technologies and also growing trend to netsourcing, enable developers to design and implement software that may soon lead to true pervasive and distributed computing. Design patterns help software engineers to tackle the challenges related to these issues by presenting comprehensive documents that address problems and their solutions in any related area. To deal with these problems, this study presents an object-oriented divide and conquer pattern along with dynamics, implementation and discussions that can be used in parallel, grid and cloud computing programming models. Paper also contains related works.
Conference Paper
Large amounts of data processing bring parallel computing into sharp focus. In order to solve the sorting problem of large-scale data in the era of internet, a large-scale distributed sorting algorithm based on cloud computing is proposed. The algorithm uses the ideas of quick-sort and merge-sort to sort and integrate the data on each cloud, which making best of clouds’ computing and storage resources. Taking advantage of the idea of parallel computing, we can reduce the computing time and improve the efficiency of sorting. By evaluating algorithm’s time complexity and organizing a simulation test, the effectiveness was verified.
Article
Sorting is a very useful method required by many academic and scientific organizations. Sorting method presented in this paper places an item at final position by one swap operation only. This method is implemented in “C”. It is applied for sorting earthquake data set of size 10,000–300,000 with the increment of 50,000. For comparison purpose, number of swap operations and CPU time are considered with bubble, selection, and Insertion sort. Presented method takes lesser computation time than others.
Article
Sorting algorithm is one of the most basic research fields in computer science. It's goal is to make record easier to search, insert and delete. Through the description of five sort algorithms: bubble, select, insert, merger and quick, the time and space complexity was summarized. Furthermore, two categories of () 2 On and (l og ) On n could be found out. From the aspects of input sequence scale and input sequence random degree, some results were obtained based on the experiments. When the size of records is small, insertion sort or selection sort performs well. When the sequence is ordered, insertion sort or bubble sort performs well. When the size of records is large, quick sort or merge sort performs well. Different application could select appropriate sort algorithm according to these rules.
Article
Full-text available
With the rapid development Wireless/Handheld (W/H) technologies, mobile learning has become a new trend in education. In spite of abundant tools and literature about mobile educational software, the lake of a web-based mobile architecture is felt. This study uses design patterns to present platform independent architecture to support development of m-learning systems for greater flexibility, agile and accurate web based software development. The paper also includes an Ajax and Decorator pattern-based method to develop robust and more interactive presentation layer. Qualitative evaluations of proposed architecture illustrate the optimization on aesthetic, content, navigation and other presentation-related metrics.
Article
Full-text available
This paper presents a pattern-oriented Platform Independent Model for the management and efficient usage of resources such as memory, threads, files, or network connections considering the common underlying architecture of different software and hardware dependent mobile network technologies and common resource management needs of these systems to benefit educational services that can be transformed to different Platform Specific Models. To illustrate the proposed method, a PIM was designed to a key resource management pattern. The evaluation results of proposed PIM shows the improvements in accurate and agile designing and maintenance of the underlying architecture.
Article
Full-text available
The matrix chain ordering problem is to find the cheapest way to multiply a chain of n matrices, where the matrices are pairwise compatible but of varying dimensions. Here we give several new parallel algorithms including O(lg 3 n)-time and n/lgn-processor algorithms for solving the matrix chain ordering problem and for solving an optimal triangulation problem of convex polygons on the common CRCW PRAM model. Next, by using efficient algorithms for computing row minima of totally monotone matrices, this complexity is improved to O(lg 2 n) time with n processors on the EREW PRAM and to O(lg 2 nlglgn) time with n/lglgn processors on a common CRCW PRAM. A new algorithm for computing the row minima of totally monotone matrices improves our parallel MCOP algorithm to O(nlg 1·5 n) work and polylog time on a CREW PRAM. Optimal log-time algorithms for computing row minima of totally monotone matrices will improve our algorithm and enable it to have the same work as the sequential algorithm of T. C. Hu and M. T. Shing [SIAM J. Comput. 11, 362-373 (1982; Zbl 0483.68041); SIAM J. Comput. 13, 228-251 (1984; Zbl 0542.68028)].
Chapter
This chapter is still of a preliminary nature. It contains some basic notions of complexity theory and outlines some well-known algorithms. In addition, less standard concepts and results are described. Among others, we treat oracle algorithms, encoding lengths, and approximation and computation of numbers, and we analyse the running time of Gaussian elimination and related procedures. The notions introduced in this chapter constitute the framework in which algorithms are designed and analysed in this book. We intend to stay on a more or less informal level; nevertheless, all notions introduced here can be made completely precise — see for instance Aho, Hopcroft and Ullman (1974), Garey and Johnson (1979).
Chapter
Once we have developed an algorithm (q.v.) for solving a computational problem and analyzed its worst-case time requirements as a function of the size of its input (most usefully, in terms of the O-notation; see ALGORITHMS, ANALYSIS OF), it is inevitable to ask the question: "Can we do better?" In a typical problem, we may be able to devise new algorithms for the problem that are more and more efficient. But eventually, this line of research often seems to hit an invisible barrier, a level beyond whch improvements are very difficult, seemingly impossible, to come by. After many unsuccessful attempts, algorithm designers inevitably start to wonder if there is something inherent in the problem that makes it impossible to devise algorithms that are faster than the current one. They may try to develop mathematical techniques for proving formally that there can be no algorithm for the given problem which runs faster than the current one. Such a proof would be valuable, as it would suggest that it is futile to keep working on improved algorithms for this problem, that further improvements are certainly impossible. The realm of mathematical models and techniques for establishing such impossibility proofs is called computational complexity.
Article
An optimum method of coding an ensemble of messages consisting of a finite number of members is developed. A minimum-redundancy code is one constructed in such a way that the average number of coding digits per message is minimized.
Book
Geometric algorithms and combinatorial optimization / Martin Grötschel ; László Lovász ; Alexander Schrijver. - Berlin u. a. : Springer, 1988. - XII, 362 S. - (Algorithms and combinatorics ; 2).
Conference Paper
We present a randomized algorithm sorting n integers in O(n√(log log n)) expected time and linear space. This improves the previous O(n log log n) bound by Anderson et al. (1995). As an immediate consequence, if the integers are bounded by U, we can sort them in O(n√(log log U)) expected time. This is the first improvement over the O (n log log U) bound obtained with van Emde Boas' data structure. At the heart of our construction, is a technical deterministic lemma of independent interest; namely, that we split n integers into subsets of size at most √n in linear time and space. This also implies improved bounds for deterministic string sorting and integer sorting without multiplication.