Professional Documents
Culture Documents
5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
ABSTRACT
The study presents a comparative study of some sorting algorithm with the aim to come up with the most efficient sorting
algorithm. The methodology used was to evaluate the performance of median, heap, and quick sort techniques using CPU
time and memory space as performance index. This was achieved by reviewing literatures of relevant works. We also
formulated architectural model which serves as guideline for implementing and evaluating the sorting techniques. The
techniques were implemented with C-language; while the profile of each technique was obtained with G-profiler. The
results obtained show that in majority of the cases considered, heap sort technique is faster and requires less space than
median and quick sort algorithms in sorting data of any input data size. Similarly, results also show that the slowest
technique of the three is median sort; while quick sort technique is faster and requires less memory than median sort, but
slower and requires more memory than heap sort. The number of sorting algorithms considered in this study for
complexity measurement is limited to bubble, insertion, and selection sorting. Future effort will investigate complexities
of other sorting techniques in the literature based on CPU time and memory space. The goal for this will be to adopt the
most efficient sorting technique in the development of job scheduler for grid computing community.
Keywords— Sorting algorithms, Comparative Study, Heap Sort, Quick Sort, Median Sort
1. INTRODUCTION
This paper presents a comparative study of sorting However, an important question of which sorting
algorithms. Sorting [4], a mechanism that organizes algorithm is the most-efficient or least-complex is yet to
elements of a list into a predefined order is important for be fully addressed. The goal of this paper is to present a
various reasons. For instance, numerical computation comparative study of some sorting algorithm with the
with estimated values (e.g. floating point representation aim to come up with the most efficient sorting algorithm.
of real numbers) is concerned with accuracy. To control The methodology used was to evaluate the performance
accuracy in computations of this kind, scientists often of median, heap, and quick sort techniques using CPU
apply sorting to actualize the goal. In string processing, time and memory space as performance index. This was
finding the longest common prefix in a set of string and achieved by reviewing literatures of relevant works. We
the longest repeated substring in a given string is often also formulated architectural model which serves as
based on sorting. To develop jobs schedules, so as to guideline for implementing and evaluating the sorting
maximize customer satisfaction by minimizing the techniques. The techniques were implemented with C-
average completion time, often requires methods (such as language; while the profile of each technique was
longest- processing-time-first rule) based on sorting. In obtained with G-profiler. The results obtained show that
the literature, various implementation solutions of in majority of the cases considered, heap sort technique is
algorithm exist for sorting. faster and requires less space than median and quick sort
algorithms in sorting data of any input data size.
199
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
Similarly, results also show that the slowest technique of evaluated theoretically and empirically. In theory, the
the three is median sort; while quick sort technique is odd-even transposition has a complexity of O(b ); such
faster and requires less memory than median sort, but
that b = 1/2 . This implies that the time will be reduced
slower and requires more memory than heap sort. The
rest part of this paper is organized as follows. Section 2 by ‘b’. Similarly, in theory parallel rank sort has a
discusses related works;. In section 3, we presented an complexity of O( ); c = 1/p. The theoretical
architectural model designed for this work;. Section 4 complexity of parallel merge sort is O(n/p log n/p) [13].
presented the algorithms design for simulating the sorting ‘P’ is number of processes. Empirical results have shown
algorithms; section 5 discusses the results obtained from that the fastest algorithm of three is the parallel merge
the evaluation of sorting techniques considered. In technique. This is followed by the odd-even transposition
sections 4; and section 6 concluded the paper; while algorithm; while the slowest is the parallel rank sorting
section 7 presented future thoughts. algorithm.
The motivation of [7] was to research sorting algorithms
2. RELATED WORKS for potential failing comparisons. It was expected that
faulty comparisons tend to occur in sorting, due to
In the literature, there are various researches on random fluctuations in the evaluation functions that
evaluating performance or complexity of sorting compares two elements. Hence, the aim of the work is
algorithms.. In [4], a comparative study of some parallel research a method that is robust against faulty
sort algorithms such as: map sort, merge sort, Tsigas- comparisons. The null hypothesis for the research is: a
Zhangs parallel quicksort, alternative quick sort, and STL very efficient (i.e. low complexity order) sorting
sort was carried out. the goal was to introduce merge sort algorithm might be susceptible to errors from imprecise
algorithm and its ability to sort n-sized array of elements comparisons than the more efficient sorting algorithms
which might implement a lot implicitly of redundant
in O( ) time complexity. The approach adopted in comparisons. The sorting algorithms considered include:
developing this algorithm was divide-and-conquer bubble sort, merge sort, quick sort, heap sort and
method. The empirical and theoretical analyzes of merge- selection sort. The result of the research supports its null
sort algorithm was presented in addition to its pseudo hypothesis. Bubble sort is the most robust sorting
codes. Merge sort algorithm was compared with its algorithms, followed by merge, quick, heap, and selection
counterparts: bubble, insertion, and selection. It was sorts. The work contributed to the state of the art by
analyzing existing sorting algorithms based on robustness
recorded the other algorithms has quadratic O( ) time.
against imprecise and noisy comparisons.
Results presented involves merge sort against insertion
In [14], performance evaluation of bubble, selection, and
sort. This shows that merge sort algorithm is significantly
insertion sort techniques were conducted. The motivation
faster than insertion sort algorithm for great size of array. of the work was based on the unprecedented growth of
Merge sort is 24 to 241 times faster than insertion sort data in knowledge-based sectors and its requirements of
using n-values of 10,000 and 60,000 respectively. Also,
mechanisms for analyzing these data which often
results show that the difference between merge and
demands sorting. Sorting techniques evaluated in this
insertion sorts is statistically significant with more than work were subjected to CPU time and memory space as
90 percent confidence. performance index. Experimental results had shown that
the most efficient of the techniques evaluated is the
Similarly, [5] gave a practical performance comparison
insertion sort techniques in both cases of performance
of sorting algorithms like: odd-even transposition sort, parameters. Similarly, it has been observed that selection
parallel rank sort, and parallel merge sort. sort is less efficient than insertion sort technique. The
In [6], robustness was studied as a function of complexity
least efficient of the techniques is the bubble sort
of some sorting techniques. Finally, [4] evaluated merge
technique.
sort empirically and theoretically to sort N-sized dataset
in O(n log n) time as the most-efficient among bubble,
3. ARCHITECTURAL MODEL
insertion, and selection sort with quadratic time
complexity.
The knowledge acquired from the literatures is being
According to [6], a great number of research works have applied in designing the architectural model presented in
addressed issues related to dedicated and parallel Figure 1. It is divided into three basic components. These
machines [12]; but only little research has been carried are: repository, shuffling module, and sorting module.
out on performance evaluations of parallel sorting This model was formulated to serve as benchmark of
algorithms on clustered station. Hence, the goal of [6] is components to be developed when evaluating
to compare some parallel sorting algorithms with overall performance of sorting algorithms. The data designed for
execution time as performance parameter. Algorithms evaluating the algorithms is stored in the repository. This
considered include: odd-even transposition sort, parallel data may be ordered or unordered in nature.
rank sort, and parallel merge sort. These algorithms were
200
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
1. for i ← 1 to n – 1 do
2. val ← A[i]
Figure 1: Architectural Mode 3. s←i
4. f ← (s - 1) / 2
4. ALGORITHM DESIGN 5. while s > 0 AND A[f] < val do
This section describes and presents the basic algorithms
which are the foundation of majority of the sorting 6. A[s] ← A[f]
algorithms. Algorithms under these categories include: 7. s←f
shuffling and swapping algorithms.
8. f ← (s - 1) / 2
4.1 Shuffling Algorithm
9. end-while
Figures 2 presents pseudo code of the shuffling
algorithm. Its theoretical complexity is O(n) and O(1) in
10. A[s] ← val
worst case and best case scenario respectively. We have 11. end-for
assumed that swapping algorithm takes a constant time
O(1) to execute in theory.
Figure 3: Make Heap Algorithim
201
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
202
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
203
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
Also, graph 2 illustrates results of an experiment with the memory space required for quick sort algorithm is the
complexities of the sorting techniques based on input same for data sizes of 10,000 and 30,000. But for other
data size against memory space. In similar manner, M- data sizes, the memory space required is proportional to
Sort, H-Sort, and Q-Sort imply median, heap and quick the input data size. Also we observed that the memory
sort techniques. We observed that for median and heap space required by median sort is 2.5 times larger than its
sorting techniques considered in this work, the memory counterparts. Heap and quick sort algorithms compete in
space is directly proportional to the input data size, while almost all the cases of input data size.
204
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
6. CONCLUSION
In conclusion, we have evaluated the performance of
median, heap, and quick sort techniques using CPU time
and memory space as performance index. This was
achieved by reviewing literatures of relevant works. We
also formulated architectural model which serves as
guideline for implementing and evaluating the sorting
techniques. The techniques were implemented with C-
language; while the profile of each technique was
obtained with G-profiler [15].
205
Vol 6. No. 5, December 2013
African Journal of Computing & ICT
© 2013 Afr J Comp & ICT – All Rights Reserved - ISSN 2006-1781
www.ajocict.net
REFERENCES
[1] Wright A., Glut: Mastering Information
through the ages, Henry, Washington D.C.,
2007.
[2] Dubitzky W., Data mining techniques in grid
computing environment, John Wiley and Sons,
West Sussex, U.K., 2008.
[3] Aremu D.R., Adesina O.O., “Web services: A
solution to interoperability problems in sharing
grid resources”, ARPN Journal of Systems and
Software, vol. 1, no. 4, pp. 141 – 148, 2011.
[4] Qin M., “Merge Sort Algorithm”, Department
of Computer Sciences, Florida Institute of
Technology, Melbourne, FL 32901.
[5] Qureshi K., “A Practical Performance
Comparison of Parallel Sorting Algorithms on
Homogeneous Network of Workstations”,
Department of Mathematics and Computer
Science, Kuwait University, Kuwait.
[6] Pasetto D., Akhriev A., “A comparative study
of parallel sort algorithms”, IBM Dublin
Research Laboratory, Dublin15, Ireland.
[7] Elmenreich W., Ibounig T., Fehérvári I.,
“Robustness versus performance in sorting and
tournament algorithms”, Acta Polytechnica
Hungarica, vol. 6, no. 5, pp. 7 – 17, 2009.
[8] George T.H., Police G., Selkow S., Algorithms
in a nutshell, O’Rielly, California, 2009.
[9] Edahiro M., “Parallelizing fundamental
algorithms such as sorting on multi-core
processors for EDA acceleration”. Asia and
South Pacific Design Automation Conference,
pp. 230 – 233, 2009.
[10] Varman P.J., Scheufler S.D., Iyer B.R., Ricard
G.R., “Merging multiple lists on hierarchical-
memory multiprocessors”, Journal of Parallel
and Distributed Computing, vol. 12, no. 2, pp.
171 – 177, 1991.
[11] Tsigas P., Zhang Y., “A simple, fast parallel
implementation of quicksort and its
performance evaluation on Sun Enterprise
10000”, 11th Euromicro Conference on Parallel
Distributed and Network-based Processing, pp.
372 – 384, 2003.
206