Sorting Algorithms A Comparative Study1
Sorting Algorithms A Comparative Study1
Sorting Algorithms A Comparative Study1
net/publication/315662067
CITATIONS READS
7 17,934
3 authors, including:
Muhammad Idrees
Government College University Faisalabad
5 PUBLICATIONS 8 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Muhammad Idrees on 27 March 2017.
Abstract – Sorting is nothing but alphabetizing, scheduling are examples of sorting. Thomas
categorizing, arranging or putting items in an Cormen, Charlese Ronald, Clifford Stein and
ordered sequence. It is a key fundamental Rivest Leiserson (2001) state “An algorithms is
operation in the field of computer science. It is any well-defined computational procedure that
of extreme importance because it adds takes some value, or set of values, as input and
usefulness to data. In this papers, we have produces some value or set of values as
compared five important sorting algorithms output”[2]. A number of sorting algorithms are
(Bubble, Quick, Selection, Insertion and Merge). available with pros and cons. Alfred Aho, John
We have developed a program in C# and Hopcroft and Jeffrey Ullman (1974) has
experimented with the input values 1-150, 1-300 classified algorithms on the basis of
and 1-950. The performance and efficiency of computational complexity, number of swaps,
these algorithms in terms of CPU time stability, usage of extra resources and recursion
consumption has been recorded and presented in [3]. The items to be sorted may be in various
tabular and graphical form. forms i.e. random as a whole, already sorted,
very small or extremely large in numer, sorted in
Key words: Quick Sort, Insertion Sort, Bubble reverse order etc. There is no algorithm which is
Sort, Merge Sort, Selection Sort, stopwatch. best for sorting all types of data. We must be
familiar with sorting algorithms in terms of their
1. Introduction suitability in a particular situation. In this paper
Arranging or sorting things or items is not an we are going to compare five (Bubble, Quick,
overnight development. Its footprints can be Insertion, Selection and Merge) sorting
traced back in 7th century BCE. Abdul Wahab algorithms for their CPU time consumption on a
and O.Issa (2009) state that King of Assyria given input in best, worst and average cases.
used the idea of arranging clay tablets for Royal Rest of the paper comprises of: 2. Related Work
Library sorted according to their shape[1]. 3. Methodology 4. Experiments 5. Results and
Sorting is not a jaguar leap but it has emerged in Discussion
parallel with the development of human mind. In 6. Conclusion 7. Future Work 8. References.
computer science, alphabetizing, arranging,
categoring or putting data items in an ordered 2. Related Work
sequence on the basis of similar properties is Jehad Alnihoud and Rami Mansi (2010) state
called sorting. Sorting is of key importance that sorting is graded as a fundamental problem
because it optimizes the usefulness of data. We in computer science[4]. Sonal Beniwal and
can observe plenty of sorting examples in our Deepti Groover (2013), after comparing Bubble,
daily life, e.g. we can easily find required items Heap, Insertion, Merge and Quick sort
in a shopping maal or utility store because the algorithms have concluded that quality of a good
items are kept categorically. Finding a word sorting algorithm is not only the speed but other
from dictionary is not a tideous task because all factors like, length, code complexity, stability,
the words are given in sorted form. Similarly, performance consistency and data type handling
finding a telephone number, name or address should also be taken into consideration[5]. Rohit
from a telephone directory is also very easy due Joshi etc (2013) in [6] have analyzed the time
to the blessings of sorting. In computer science, complexity of Bucket Sort, Counting Sort, Radix
sorting is one of the most important fundamental Sort on input 1,2,3….10 and concluded that non-
operations because of its pivotal applications. comparison based algorithms are better by O(n)
Priority scheduling and shortest job first instead of comparison based O(n log n). Aliyu
Page ‐ 1
930 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
International Journal of Computer Science and Information Security (IJCSIS),
Vol. 14, No. 12, December 2016
Ahmed and Dr. Zirra (2013) in [7] have Merge, Quick and Heap sort algorithms are
compared Insertion and Quick sort algorithms faster than the remaining two when the input
on both integer and character arrays concluded size is very large. In [12] Pankaj Sareen (2013)
that performance of insertion short is better than has compared Bubble, Insertion, Selection,
quick sort. Both algorithms are for sorting small Merge and Quick sort algorithms on the input
number of items. CPU time consumption while values 10, 100, 1000 and 10000. The
sorting integer arrays is very low as compared to comparison was based on average case only.
character arrays. In [8] Nidhi Chhajed and The average running time of all the algorithms
Simarjeet Singh Bhatia (2013) have compared was noted on these inputs and presented
Quick, Heap and Insertion Sort algorithms in graphically. It was concluded that the most
terms of time complexity and various efficient algorithm was Quick Sort. In [13 & 14]
performance factors. Random numbers between several studies (Thomas Cormen, et. al. 2009;
10,000 to 30,000 have been used as input data. Juliana Pena Ocampo, 2008) suggest state that
They have concluded that insertion sort all algorithms perform O(n2) in their worst case,
algorithm is slower than heap and quick sort. All Quick Sort is the only algorithm which have
of them have worst case time complexity as N2. average and best runtime of O(nLogn). It means
But quick sort performed better than the other that Quick Sort is better than Insertion, Bubble
two. As the input increases insertion sort and Selection sort in average case, for
performs very poorly and shows exponential sufficiently large input.
growth. In [9] Ashutosh Bharadwaj and
Shailendra Mishra (2013) have compared 3. Methodology
Insertion, Bubble, Selection, Merge and Index Empirical comparison is always machine
Sort algorithms on 10, 100 and 10001000 inputs dependent. It is essential to explicitly describe
and concluded that performance of Index Sort is the machine used for experiments in particular to
better on all input values. It consumes lesser facilitate the researchers who intend to reverify
CPU time than others on small input. It takes the results. A program developed in C# has
more CPU time than Selection, Merge and been used for calculation of CPU time taken by
Bubble Sort for larger input. Jehad Hammad each algorithm. The data set used for this
(2015) states in his comparative study on purpose consists of 1-150, 1-300, and 1-950 in
HornerEval, Linear Search, Towers, Binary best, worst and average cases. The program was
Search, Insertion, Max, Min, MaxMin, Merge, executed on Windows 7 (64 bit), Service Pack 1,
Quick, SelectionSort, Heap, Bubble and Gnome Computer used for this purpose was CPU T7100
Sorting algorithms on 5000, 10000, 20000 and @ 1.80 GHz, Intel(R) Core(TM)2 Duo. Memory
30000 input values that Gnome sorting installed was 2.00 GB. Consumption of CPU
algorithm is the quickest in best case. Selection time from all the algorithm was noted using
sort is quicker than bubble sort and gnome sort Stopwatch after running the program on all the
on random data. He has further analyzed a inputs. The results were calculated after
drawback of selection sort which continues tabulation and then their graphical representation
sorting the items it they are already arranged, was developed using MS Excl.
while gnome and bubble sort algorithms swap
the items if required[10]. In [11] Gaurav Kumar 4. Experiments & Results
etc (2013) have compared Bubble, Insertion, Stopwatch provides high accuracy when used for
Quick, Merge and Heap sorting algorithms on comparison of algorithms for their efficiency.
100000, 300000, 500000, 700000, 1000000, But it is not 100% accurate. In [15] Thomas
1500000 input values. After comparing the data Maierhofer (2010) states that Stopwatch may
empirically the algorithms were ranked in the provide results 25%-30% different for the same
following order on the basis of their speed. code excuted repeatedly on the same machine.
1. Merge We have run our program 5-times on the same
2. Quick input and have taken the average of 5-results to
3. Heap achieve better accuracy as in [16] Pankaj Sareen
4. Insertion (2013) has run his program five times on the
5. Bubble same input to calculate average running time.
Page ‐ 2
931 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
International Journal of Computer Science and Information Security (IJCSIS),
Vol. 14, No. 12, December 2016
TABLE – 1 TABLE – 3
Comparison on input 1 to 150 Best Case Comparison on input 1 to 150 Average Case
Time Consumption in microseconds Time Consumption in microseconds
Algo on input Value 1-150 (Best Case) Algo on input Value 1-150 (Average Case)
1 2 3 4 5 Average 1 2 3 4 5 Average
Bubble 2260 2301 2106 2460 2377 2300.80 Bubble 4317 4070 3795 3769 4026 3995.40
Quick 2941 3261 2897 3018 2927 3008.80 Quick 4442 4311 4205 4085 5653 4539.20
Selection 1845 2389 2279 2003 1865 2076.20 Selection 2845 2910 2847 2791 3629 3004.40
Insertion 1467 2018 1570 1370 1429 1570.80 Insertion 2386 2365 2565 2321 2898 2507.00
Merge 3763 4525 4248 5695 4510 4548.20 Merge 5579 5664 5734 6183 6803 5992.60
Graph – 1 Graph – 3
Comparison on input 1 to 150 Best Case Comparison on input 1 to 150 Average Case
5992.60
4174.60 6000
4548.2
4500.00
4174.60
3995.40
4000.00 5000
3176.00
3176.00
3004.40
3500.00
2813.20
3008.8
2507.00
2061.80
2076.2
1867.40
2500.00 2061.80
3000
1570.8
2000.00 1867.40
1500.00 2000
1000.00
1000
500.00
0.00 0
Bubble Quick Selection Insertion Merge Bubble Quick Selection Insertion Merge
Page ‐ 3
932 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
International Journal of Computer Science and Information Security (IJCSIS),
Vol. 14, No. 12, December 2016
TABLE – 4 TABLE – 6
Comparison on input 1 to 300 Best Case Comparison on input 1 to 300 Average Case
Time Consumption in microseconds Time Consumption in microseconds
Algo on input Value 1-300 (Best Case) Algo on input Value 1-300 (Average Case)
1 2 3 4 5 Average 1 2 3 4 5 Average
Bubble 3741 3746 3419 3582 3642 3626.00 Bubble 6774 6882 7091 7341 6935 7004.60
Quick 4452 4159 3977 3975 4098 4132.20 Quick 4530 4632 4507 4513 4215 4479.40
Selection 2956 2627 2699 2627 2782 2738.20 Selection 4458 4171 4195 4021 4100 4189.00
Insertion 1323 1319 1333 1324 1616 1383.00 Insertion 3852 3505 3485 3314 3929 3617.00
Merge 4602 5014 4334 4311 4729 4598.00 Merge 6571 7140 6305 6850 6638 6700.80
Graph – 4 Graph – 6
Comparison on input 1 to 300 Best Case Comparison on input 1 to 300 Average Case
8000
6700.8
4971 6000
4479.4
4889.8
4132.2
4889.8
4364
5000 4364
4598
4189
5000
3626
4000
3273.8
3617
2738.2
3000
3000
2000
2000
1383
1000
0 1000
Bubble 0
Quick
Selection Bubble
Insertion Quick
Merge Selection
Insertion
Merge
Page ‐ 4
933 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
International Journal of Computer Science and Information Security (IJCSIS),
Vol. 14, No. 12, December 2016
TABLE – 7 TABLE – 9
Comparison on input 1 to 950 Best Case Comparison on input 1 to 950 Average Case
Time Consumption in microseconds Time Consumption in microseconds
Algo on input Value 1-950 (Best Case) Algo on input Value 1-950 (Average Case)
1 2 3 4 5 Average 1 2 3 4 5 Average
Bubble 21744 23575 18279 21566 19441 20921 Bubble 44499 57172 45139 44252 51804 48573.20
Quick 17857 18492 17946 18682 19954 18586 Quick 5013 5609 5332 5034 5403 5278.20
Selection 11998 12301 12884 12054 12414 12330 Selection 17906 18356 17925 18104 18199 18098.00
Insertion 1369 1812 1639 1400 1465 1537 Insertion 15427 25973 26047 15326 15985 19751.60
Merge 15137 15161 11863 15196 15399 14551 Merge 17672 23301 17500 17310 16836 18523.80
Graph – 7 Graph – 9
Comparison on input 1 to 950 Best Case Comparison on input 1 to 950 Average Case
25000 50000 48573.2
20921
18586.2
20000 40000
40000 50000
36539.4
35000
40000
30000
20921
17666.6
20493.2
25000 30000
19751.6
18586
14952.2
18098
18523.8
20000 20493.2
17666.6 14952.2
12330
12841.6
20000
14551
15000
5278.2
5000
0 0
Bubble Bubble Quick
Quick Selection
Selection Insertion
Insertion Merge
Merge
Page ‐ 5
934 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
International Journal of Computer Science and Information Security (IJCSIS),
Vol. 14, No. 12, December 2016
Page ‐ 6
935 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
International Journal of Computer Science and Information Security (IJCSIS),
Vol. 14, No. 12, December 2016
MSD Radix sort and Bucket sort, etc) can be [9] Bharadwaj, A., & Mishra, S. Comparison
carried out. of Sorting Algorithms based in Input
3. Performance comaprison of the sorting Sequences, International Journal of
algorithms can be made on the same input with Computer Applications, Vol. 78, No. 14
integers and characters separately. All of them (2013).
can be ranked according to their efficiency on
[10] Hammad, J. A Comparative Study between
both type of inputs separately with analysis of
Various Sorting Algorithms, International
their behavior on varying input size.
Journal of Computer Science and Network
Security (IJCSNS), Vol 15, No. 3 (2015).
8. References:
[1] Wahab, A., Issa, O.A. Fundamentals of [11] Kumar, G. & Ghugh, H. Empirical Study of
Library & Information Sciences, (1st ed.). Complexity Graphs for Sorting Algorithms,
Cataloguing-in-Publication Data, Ilorin International Journal of Computer,
Communication and Information
(2009).
Technology (IJCCIT), Vol. 1, No. 1 (2013).
[2] Cormen, T.H., Leiserson, C.E., & Rivest, [12] Sareen, P. Comparison of Sorting
R.L. Introduction to Algorithms (2nd ed.). Algorithms (On the Basis of Average
Prentice Hall of India private limited, New Time), International Journal of Advanced
Delhi-110001 (2001). Research in Computer Science & Software
Engineering, Vol. 3, Issue 3 (2013).
[3] Aho A., Hopcroft J., and Ullman J. The
Design and Analysis of Computer [13] Cormen, T. H., Leiserson, C.E., & Rivest,
Algorithms, Addison Wesley (1974). R.L. Introduction to Algorithms (3rd ed.).
[4] Alnihoud, J., & Rami, R. An Enhancement MIT Press and McGraw-Hill (2009).
of Major Sorting Algorithms, The [14] Pena, J. O. An empirical comparison of the
Intational Arab Journal of Information runtime of five sorting algorithms,
Technology, Vol. 7, No. 1, January (2010). International Baccalaureate Extended Essay
[5] Ben, S. & Deepti, Gr. Comparison of (2008).
Various Sorting Algorithms: A Review, [15] Thomas Maierhofer Performance Tests:
International Journal of Emerging Research Precise Run Time Measurements with
in Management & Technology, Vol., 2,
System.Diagnostics.Stopwatch. (2010),
Issue 5 (2013).
[6] Joshi, R., Panwar, G.P., Pathak, P. (2013). Retrieved from
Analysis of Non-Comparison Based http://www.codeproject.com/Articles/6196
Sorting Algorithms: A Review, 4/Performance-Tests-Precise-Run-Time-
International Journal of Emerging Research Measurements-wi
in Management & Technology.
[16] Sareen, P. Comparison of Sorting
[7] Ahmed M. Aliyu, Dr. P.B. Zirra. A Algorithms (On the Basis of Average
Comparative Analysis of Sorting Time), International Journal of Advanced
Algorithms on Integer and Character Research in Computer Science & Software
Arrays, The International Journal of Engineering, Vol. 3, Issue 3 (2013).
Engineering and Science (IJES), Vol 2,
Issue 7 (2013).
[8] Chhajed, N., & Bhatia, S.S. A Comparison
Based Analysis of Different Types of
Sorting Algorithms with their
Performances, Indian Journal of Research
Paripex, Vol. 2, Issue. 3 (2013).
Page ‐ 7
936 https://sites.google.com/site/ijcsis/
ISSN 1947-5500
View publication stats