In our thesis work, we try to find out the efficiency of several sorting algorithms and generate a comparative report according to performance, based on experimental data size and data order for all algorithm. To do this we have researched, analyzed about 9 different types of well-known sorting algorithms. We convert the algorithms to programmable code, compile and run with different set of data. We keep the sorting algorithm’s description as it is. We give focus on, how the algorithms work, considering their total operation count (assignment count, comparison count) and complexity based on our same data set for all algorithm. We write programming code for each sorting algorithm in C programming language. In our investigation, we have also worked with big and small data for different cases (ordered, pre-ordered, random, disordered) and put their result in different tables. We show the increasing ratio to compare the result. we also show the data in graphical chart for view comparative report in same window. We mark their efficiency with point and ranked them. At last we discussed their result of efficiency in a single table. We modify the merge sort and try to make an improved tri-merge sorting algorithm that is more efficient than marge sort. Theoretically if we divide and conquer with higher number its result is better, some paper exists on it, but to manage the algorithm, there cost lot of operations count. Like, if we consider quadratic divide-conquer, its manage complexly is huge than binary divide-conquer that why we generally use binary merge. We found trimerge is theoretically and practically true based on investigation data set. Tri-marge take some more compare operation for manage and sort when data remain 1 or 2 at last stage, whereas binary merge don’t need such compare. But for big data size tri-merge gain lot of operation count that give significant result that declare tri-merge is more efficient than merge sort algorithm. We also experiment with penta-merge algorithm which give more better result but algorithm and implementation is too complex.
We shall try to define the tri-merge algorithm so that it can be used to implement in any
programming language. It will help students, researchers to use the algorithm, as like we
got the various algorithm structure over the internet.
2. Project Presentation
On
Efficiency of sorting algorithms
Course No: 490
Session: 2001- 2002
Class Roll No: Jn-262
Registration No: 3293/1997-1998
Supervised by: Dr. Amal Krishna Halder
3. What is sorting algorithms
• The word Sort refer to arrange the records
according order which may be ascending order
or descending order.
• The word Algorithm refer to technique or
process of sorting the records.
4. What we have done
• Review various sorting algorithms with the help of
Internet, Library books and our project guide.
• Implement the algorithms by a well known programming
language C/C++ and test it for various data.
• We contribute something new algorithm structure in the
sorting algorithm literature.
• We analyzed comparatively and try to find efficiency
among them.
• We try to make a Conclusion about the efficiency of
sorting algorithms.
5. Why we choose sorting algorithms
• There are many reasons why sorting algorithms is of
• Computer can perform million/billion time faster
interest to computer scientists and mathematicians.
operations than human. As for example, to find a specific
data among billion of data computer will take few
• seconds.
Some algorithms are easy to implement, some algorithms
take advantage of particular computer architectures, and
• some fast computer search a dataclever. Someits very
How algorithms are particularly depends on are
efficient in every stage, some are inefficient for a
processing power. Processing power depends on
particular size and type of data. to search a specific data
processing technique. It is easy
if it has been sorted earlier. So sorting takes very
• important role for searching data. find out the efficiency
In our project, our main aim is to
of various types of sorting algorithm.
6. Type of sorting
• Internal: if the records that it is sorting are in
main memory. e.g. Bubble, Quick, Shell etc.
• External: if the records that it is sorting are with
the help of auxiliary storage. e.g. Radix, Merge,
Tri-merge(newly proposed)
7. A sort also can classified as:
• Recursive: if recursive function (the function
which calls itself in the function) is used .
e.g. Merge, Quick, Tri-merge(newly proposed)
etc.
• Non-recursive: if it is not used recursive
function e.g. Bubble, Insertion, Shell etc.
8. Overview
• After reviewing various sorting algorithm we
choose some commonly used sorting algorithm
that will be listed afterwards.
• For each algorithm we try to describe
derivation and algorithm with the same
example for clear understand.
10. A new approach for sorting algorithm
literature
• Reviewing various sorting algorithm our knowledge has
been enriched. We try to work with ternary tree structure
for sorting algorithm where as generally used binary tree
structure.
• After facing many problem finally we able to construct a
successful sorting algorithm which probed to be more
efficient than binary one.
• Since it uses ternary tree structure and merging technique
we named it Tri-merge Sort.
• As far as our knowledge goes, this ternary tree structure
has not yet been used for sorting algorithm.
11. Problem faced
• At first we faced the problem that if data size can be
expressed as 3 i (i=1,2…k) then it works properly
because it splits equally and merge without missing
• But if data size is not an exact multiple of 3 then it
cannot be split equally and cannot merge from three
files recursively.
• We fixed the problem by ensuring that data will be
split recursively until 1 or 2 data remain. This last step
is treated individually without recursive call and will be
sort among themselves.
12. Tri-merge Sort
Formulation:
Tri-merge is a new proposed technique for sorting
data. It uses the attractive features of the sorting methods
as like of merge sorting. Tri-merge uses ternary tree
structure and recursive function.
The procedure of Tri-merge sort is completed in
two phases:
Phase-1: Split in to 3 parts recursively.
Phase-2: Merge to 1 part from 3 ordered parts recursively.
13. Phase-1: Split
• In this stage total data of the given list split into
3 parts.
• Each part consequently split 3 parts recursively
until 1 or 2 elements remain.
• When two data remain in a part they are sorted
among themselves.
• The split procedure will be shown afterward by
animation.
14. Phase-2: Merge
• In this phase every 3 split parts become 1 part
and are sorted among themselves.
• This process continues until all data become
one part and finally we get completely sorted
data.
• The merge procedure will be shown afterward
by animation.
15. Splitting Recursively
8 5 2 7 1 3 9 2 6
Split to 3 parts Recursively until 1 or 2 data remain
8 5 2 7 1 3 9 2 6
8 5 2 7 1 3 9 2 6
16. Merging Recursively
8 5 2 7 1 3 9 2 6
2 5 8 1 3 7 2 6 9
Compare first element from three files and find smallest one
Which will be merge to final 3 Sorted files tohere..
Final Merge From list as like describing 1 Sorted file
This process will be continue
until all data are merged
1 2 2 3 5 6 7 8 9
Now we get sorted list
17. Tri-mergeSort( a[L,....,R], L, R )
{ n=R-L+1 (number of element calculated from index position)
IF (n>2) THEN
{
m1 = n/3 (First midpoint)
m2 = 2*m1 (Second midpoint)
Tri-mergeSort ( a[L,….,m1], L, m1 )
Algorithm of Tri-merge sort
Tri-mergeSort ( a[m1+1,….,m2], m1+1, m2 )
Tri-mergeSort ( a[m2+1,….,R], m2+1, R )
Tri-merge ( a[L,….,R], L, m1+1, m2+1, R )
} in
ELSE IF (n = 2) THEN
{
Structural PseudoCode
IF ( a[L] > a[R] )
{
temp = a[L]
a[L] = a[R]
a[R] = temp
}
}
}
18. Tri-merge ( a[L,….,R], L, m1, m2, R)
{ part1 = a[L,…,m1-1]; part2 = a[m1,…,m2-1]; part3 = a[m2,…,R]
TempArray[L,…,R]; n = R-L+1
IF ( n > 2 )
{ WHILE( part1, part2 and part3 has elements )
Comparing from 3 parts find minimum and set to TempArray.
WHILE( part1 and part2 has elements )
Comparing from 2 parts find minimum and set to TempArray.
WHILE( part2 and part3 has elements )
Comparing from 2 parts find minimum and set to TempArray.
WHILE( part1 and part3 has elements )
Comparing from 2 parts find minimum and set to TempArray.
WHILE( part1 has elements )
set to TempArray.
WHILE( part2 has elements )
set to TempArray.
WHILE (part3 has elements)
set to TempArray.
}
RETURN TempArray
}
19. void TriMergeSort( int a[], int L, int R, long int asscount[],long int comcount[])
{
int noOfEle=R-L+1;
int m1,m2,part,t;
comcount[0]++;
if(noOfEle>2)
{
part=(R-L+1)/3;
m1 = L+part-1;
Complete program of
m2 = L+2*part-1;
asscount[0]+=3;
Tri-merge Sort
TriMergeSort(a,L,m1,asscount,comcount);
TriMergeSort(a, m1+1,m2,asscount,comcount);
TriMergeSort(a, m2+1,R,asscount,comcount);
TriMerge(a,L,m1+1,m2+1,R,asscount,comcount);
}
else if(noOfEle==2)
{
comcount[0]+=2;
if(a[L]>a[R])
{
asscount[0]+=3;
t=a[L];
a[L]=a[R];
20.
21. Efficiency Analysis
Efficiency of sorting algorithm depends on the
following criteria:
• How quickly (how much time require) data is sorted.
CPU time depends on how many operation (assignment
and compare) count are required for the algorithm
• How they work for small data
• How they work for big data
• How they work for random data
• How they work for preordered, disordered data and so
on.
22. To achieve our goal we have try to do the
following task
Since efficiency (time) depends on number of operations
so we try to find out the total number of assignment and
compare operations involved.
• Input data is prepared as random order by C/C++
programming command.
• To get effect on number of operations for small and big
data we find out total number of operations for 50, 200,
400, 600, 800 data.
• We had a limitation to work with huge data (e.g. we have
used earlier version of C/C++ compiler, Limited
memory size of the computer.)
23. To achieve our goal we have try to do the
following task
For comparative analysis we arrange total number of
operation count in different table with different number
of data (e.g. 50, 200, 400, 600, 800) including 100%, 80%,
10%, random, totally disordered.
• To compare the result clearly we show them graphically
so that one can get the picture at a glance.
• Analyzing the obtained data we try to find out an
approximation function of operation count f(n), where n
is the number of data. To get the function we use the
technique of interpolation. This function is also serves
an indication about the efficiency of the algorithm.
31. Bubble Sort is a very slow way of sorting; its
main advantage is the simplicity of the
algorithm.
Insertion Sort is much efficient for ordered,
preordered and small data. For disorder and
large data its efficiency goes inversely.
Selection sort works nearly same for all types
(ordered, preordered, random, disordered) of
data. It is more efficient for small data than
large one.
Replacement sort is also a slow procedure as
bubble sort, it is not so efficient one.
Heap sort works well for disordered and data
than preordered data. It also works well for
big data.
32. Shell sort is more efficient for ordered data; it
also works very well for small data but very
slow for disordered data.
Radix sort is much more efficient than any
other sorting algorithm. It works well for all
types of ordered, disordered and random
data; basically it gives exactly the same
number of operations for all of those types.
In our observation
Quick sort is more efficient for random data. It
is bad for fully ordered and fully disordered
data.
Merge sort gives nearly same number of
operation for all types of data. It is more
efficient for big data.
Tri-merge sort gives much better result than the
merge sort, i.e. it is more efficient than
merge.
33. Ranking of sorting algorithm:
It is very difficult to make ranking order of sorting algorithm according to
their efficiency. Some works very well for small data and some well for big
data. Similarly some works well for preordered data some works well for
random data. After all we try to find out a general rank order for average
situation.
Radix sort
Quick sort
Heap sort
Tri-merge (newly proposed)
Merge sort
Shell sort
Insertion sort
Selection sort
Replacement sort
Bubble sort.
34. Sort
Bubble Inser Selec Replace Tri-
Heap Shell Radix Quick Merge
tion tion Ment merge
Type
Most Most Most Fairly Fairly
Algorithm Most Easy Easy Easy
Easy Hard Hard
Easy Hard
Hard Hard
Fairly Fairly Very Very
For Random Data Very Bad
Bad
Bad Fairly Bad Good
Good Good good
Good Good
Very Bad Fairly Very Very Very Very Fairly
For Ordered Data Good Bad
Bad Bad
Good Good bad Good
Good
Very Fairly Very Very
For Disordered Data Very Bad
Bad
Bad Bad Good
Good Good bad
Good Good
Very Very Fairly Fairly
For Small Data Very Bad Good Bad Very Bad Good Good
Good Good Good Good
Fairly Very
For Big Data Very Bad Bad Bad Vary Bad Good
Bad Good
Good Good Good
1.5* 28* 39* 5* 14* 36* 32*
2 2 n2 2 nLog10 n nLog10 n nLog10 n nLog10 n nLog10 n nLog10 n
Obtained Complexity 2* n n 1.7* n
Conclusion Table at a glance