Sunteți pe pagina 1din 6

International Journal of Electrical & Computer Sciences IJECS-IJENS Vol: 11 No: 02 19

115002-3838 IJECS-IJENS April 2011 IJENS


I J E N S



ABSTRACT Optimized Selection Sort Algorithm is a new
sorting algorithm that has been developed to address the
shortcomings of the current popular sorting algorithms. The
goal of this research is to perform an extensive empirical
analysis of Optimized Selection Sort against Selection Sort
and Insertion Sort Algorithms. The results proved that
Optimized Selection Sort is much more efficient than
Selection Sort Algorithm; Furthermore analysis supports the
fact that Optimized Selection Sort is better than Insertion Sort
in worst case scenario.


Key Words: Optimized Selection Sort, Worst Case,
Efficiency, Sorting Algorithm

I. INTRODUCTION

ORTING algorithms are the basic foundations of practical
Computer Science, and therefore, the analysis and design
of useful sorting algorithms has remained one of the most
important research area in the field. Despite the fact that,
several new sorting algorithms being introduced, the large
number of programmers in the field depends on one of the
comparison-based sorting algorithms: Bubble, Insertion,
Selection sort etc. The new algorithms are usually not being
used as much because they are not as general purpose as
comparison-based sorting algorithms, usually require more
alteration to work with new classes and data types and in large
cases, do not perform as well as expected due to poorer
locality of reference caused by linear passes through the array
[1] [2] [3] [4].

It is necessary for a new algorithm to be acknowledged and
used in the field of Computer Science, the process must be
shown to have as good as performance to the abovementioned
sorting algorithms and be easy to use, implement, and debug.
Better performance will get programmers interested in the


algorithm, and ease-of-use will be the final determinate in
changing the programmers sorting preference. The easiest,
most time efficient way to accomplish a task is usually
preferred, and the comparison-based sorts tinted here offer
excellent performance and adaptability to any type of record
or data type to be sorted [5][6][7].

Insertion Sort and Selection Sort have been around for over
half a century, and have been taught widely in the academic
Computer Science community. These algorithms are
established and well documented with literally dozens of
thousands of published empirical analyses comparing and
contrasting performances, highlighting theoretical boundaries,
and recommending preferred solutions. This paper is no
different in this aspect. However, this paper does reveal new
information on a newly developed comparison-based sorting
algorithm based on the Selection Sort Algorithm, known as
Optimized Selection Sort Algorithm [8] [9] [15].

OSSA also referred to as Optimized Selection Sort Algorithm,
is a new in place comparison-based sort. Logic of OSSA based
on the old selection sort algorithm. The main difference in old
SS and new OSSA is that the former sorts the data from one
end i.e from largest element of array to smallest element or
from smallest to largest but the later starts sorting from both
ends and finds the largest and smallest data elements of array
in single iteration and place them at their proper locations then
during second iteration it sorts the second largest and second
smallest elements from the remaining array data and place
them in their appropriate location in the array. Similarly it
sorts rest of the data elements and put them in their proper
positions. OSSA sort the data in half iterations as compared to
old SS. It sorts two data elements at a time, which is why it
minimizes the sorting time up to 50%. Other characteristics of
this algorithm are as under [15].
x It is an in place algorithm.
x It is simple.
x Although it is O (n
2
) Algorithm, yet it is faster than
all algorithms of this order.
Optimized Selection Sort Algorithm is faster than
Insertion Sort Algorithm: a Comparative Study
Sultanullah Jadoon
1
, Salman Faiz Solehria
2
, Mubashir Qayum
3
,
1. Department of Information Technology, Hazara University, Haripur Campus, 2. Sarhad
University, Peshawar, 3. National University of Computer and Emerging Sciences, Peshawar
Campus.
sultanullah@gmail.com, ss_suit@yahoo.com, mubashir.qayyum@nu.edu.pk
S
International Journal of Electrical & Computer Sciences IJECS-IJENS Vol: 11 No: 02 20

115002-3838 IJECS-IJENS April 2011 IJENS
I J E N S
x It is two times faster than old SS and Almost as
x It is a Stable algorithm.
x It performs less data exchange operation than bubble
or insertion sort algorithm of this order.

II. SELECTION SORT ALGORITHM

A. Selection Sort

It is one of the easiest and most useful sorting algorithms for
dealing with small amount of data set. Even though it
performs a lot of comparisons, but it performs the least
amount of data moving. Thus, if your data has small keys but
large data area, then selection sorting may be the quickest
[15].

B. Pseudo Code and Execution Time of Individual
Statement of Old Selection Sort

Algorithm SelectionSort (X, n) Z
X[0..n-1]


S.
No
Iteration Cost Times
1
FOR | r - 1 TO 0


2
lrdex0lLare 0


3
FOR j 1 TO r


1
|l (X[j|>X[lrdex0lLare))


5
lrdex0lLare j



Lare X[lrdex0lLare|


Z
X[lrdex0lLare| X[||


8
X[|| Lare




C. Best-Case Time Complexity of Old Selection Sort.

For the best-case scenario when we have all


Let



Then replacing the values of we have



Thus here in best-case, the complexity of execution time of an
algorithm shows the lower bound and is asymptotically
GHQRWHGZLWK7KHUHIRUHE\LJQRULQJWKHFRQVWDQWDEFDQG
the lower terms of n, and taking only the dominant term i.e. n
2
,
then the asymptotic running time of selection sort will be
Q
2
DQG ZLOO OLH LQ RI VHW RI DV\PSWRWLF IXQFWLRQ LH Q
2
).
Hence we can say that the asymptotic running time of old SS
will be:



D. Worst - Case Time Complexity.

Now for the worst-case scenario when we have all

so
we have
International Journal of Electrical & Computer Sciences IJECS-IJENS Vol: 11 No: 02 21

115002-3838 IJECS-IJENS April 2011 IJENS
I J E N S


(Eq: 01)

Let




If we suppose

and
put it in Equation 01
Then




Thus here in worst-case, the complexity of execution time of
an algorithm shows the upper bound and is asymptotically
denoted with Big-O. Therefore by ignoring the constant a, b,c
and the lower terms of n, and taking only the dominant term
i.e. n
2
, then the asymptotic running time of selection sort will
be of the order of O(n
2
) and will lie in of set of asymptotic
IXQFWLRQ LH Q
2
). Hence we can say that the asymptotic
running time of old SS will be:





It means that the best and worst case asymptotic running time
of selection sort is same i.e

however there may be little difference in actual


running time, which will be very less and hence ignored.

III. INSERTIONSORT ALGORITHM



A. Insertion Sort

Insertion sort algorithm is also one of oldest, easiest and most
useful sorting algorithms for dealing with modicum of data
set. If the first few objects are already sorted, an unsorted
object can be inserted in the sorted set in proper place [10].

B. Pseudo Code & Execution Time of Individual
Statement of Insertion Sort


Algorithm InsertionSort (X, n) Z
X[0..n-1]

S.No Iteration Cost Times
1 FOR j 2 TO |erl|[X|


2 DO |ey ;[M|


3 Pul ;[M| |rlo l|e
sorled sequerce ;[1
. . M - 1|
0
1 L M - 1


5 WHILE L > 0 ard ;[L| > |ey


DO ;[L 1| ;[L|


Z L L - 1


8 ;[L 1| |ey




C. Best-Case Time Complexity of Insertion Sort.



Equation 01

If t
j
= 1 for j = 2, 3, ..., n and the best-case running time can be
computed as follows:


Suppose
International Journal of Electrical & Computer Sciences IJECS-IJENS Vol: 11 No: 02 22

115002-3838 IJECS-IJENS April 2011 IJENS
I J E N S


And

Then

The punch line here is that the while-loop in line 5 executed
only once for each j. This happens if given array A is already
sorted.
= O(n)
It is a linear function of n.

D. Worst-Case Time Complexity of Insertion Sort.


When t
j
= j for j = 2, 3, ..., n then the worst-case running time
can be computed from equation (1) as follows:

(Eq: 02)


If we suppose

and
put it in Equation 02
Then

Eq: 03

Suppose




Then



This running time can be expressed as

for
constants a, b, and c that again depends on the statement costs
c
i
. Therefore, is a quadratic function of n.
We usually concentrate on finding the worst-case running
time: the longest running time for any input size n.
IV. OPTIMIZED SELECTION SORT ALGORITHM
(OSSA)

A. Optimized Selection Sort Algorithm

The three main characteristics of this algorithms is that, it is
in-place, stable and easy to understand as compared to other
algorithms of order O(n
2
) [15].

The working mechanism of OSSA is that it starts sorting the
array from both ends. In a single iteration, first the smallest
and largest element in the array are searched, and then both at
the same time are placed at the specific location. This process
is continued until the whole array is sorted [15].

Even though the order of OSSA is still O(n
2
), but its
performance level has been very much improved as compared
to other sorting algorithm of the said order i.e selection sort,
insertion sort etc [15].

B. Pseudo Code & Execution Time of Individual
Statement of Optimized Selection Sort Algorithm

Algorithm OSSA (X, n) Z
X[0..n-1]

S# Iteration Cost Times
1 | 0


2 lor | r - 1 lo |


3 lrdex0lLarelrdex0l3ra|||

1 lor j| 1 lo |


5 |l (X[j| > X(lrdex0lLare|)


lrdex0lLare j


Z |l (X[j| < X[lrdex0l3ra|||)


8 lrdex0l3ra|| j


9 Lare X[lrdex0lLare|


10 3ra|| X[lrdex0l3ra|||


11 X[lrdex0lLare| X[||


12 X[lrdex0l3ra||| X[||


13 |l (lrdex0lLar==|)
Terp X[||


International Journal of Electrical & Computer Sciences IJECS-IJENS Vol: 11 No: 02 23

115002-3838 IJECS-IJENS April 2011 IJENS
I J E N S
X[|| Lare
X[lrdex0l3ra||| Terp
11 E|se X[|| Lare
Terp X[||
X[|| 3ra||
X[lrdex0lLare| Terp


15 E|se X[|| 3ra||
| | 1


C. Best-Case Time Complexity of Optimized Selection
Sort.


Let





A. Worst-Case Time Complexity of Optimized Selection
Sort.


If we put values of all Cs equal to one then we get


International Journal of Electrical & Computer Sciences IJECS-IJENS Vol: 11 No: 02 24

115002-3838 IJECS-IJENS April 2011 IJENS
I J E N S


V. COMPARISON OF SELECTION SORT,
INSERTION SORT AND OPTIMIZED
SELECTION SORT ALGORITHM

Below is the table representing the calculated time, when
multiple values of n are used.




Below is the line graph plotted in response of data given in
above table.



The graph shows that optimized selection is far better than its
competitor algorithms of the same order of O (n
2
).

Conclusion


OSSA is basically based on the logic of old Selection Sort, but
it perform less amount of iteration thats why it save almost
fifty percent of the execution time. OSSA is a new comparison
based sorting algorithm, with an

order complexity, yet


it is the fastest of its kinds, like selection and insertion sort in
the worst case. The results proved the claim.

REFERENCES
[1] Flores, I. "Analysis of Internal Computer Sorting". J.ACM 7,4 (Oct.
1960), 389- 409.
[2 ] G. Franceschini and V. Geffert. "An In-Place Sorting
with O (n log n) Comparisons and O (n) Moves". In Proc.
44th Annual IEEE Symposium on Foundations of Computer
Science, pages 242-250, 2003.
[3] Knuth, D."The Art of Computer programming Sorting
and Searching", 2nd edition, vol.3. Addison- Wesley, 1998.
[4] Hoare, C.A.R. "Algorithm 64: Quick sort". Comm. ACM 4,7 (July
1961), 321.
[5] Soubhik Chakraborty, Mausumi Bose, and Kumar Sushant, A Research
thesis, On Why Parameters of Input Distributions Need be Taken
Into Account For a More Precise Evaluation of Complexity for Certain
Algorithms.
[6] D.S. Malik, C++ Programming: Program Design Including Data
Structures, Course Technology(Thomson Learning), 2002,
www.course.com.
[7] D. Jimenez-Gonzalez, J. Navarro, and J. Larriba-Pey. CC-Radix:
"A Cache Conscious Sorting Based on Radix Sort". In Euromicro
Conference on Parallel Distributed and Network based Processing,
pages 101-108, February 2003.
[8] J. L. Bentley and R. Sedgewick. "Fast Algorithms for Sorting and
6HDUFKLQJ6WULQJV$&06,$062'$
[9] Flores, I."Analysis of Internal Computer Sorting". J.ACM 8, (Jan.
1961), 41-80.
[10] Williams, J.W.J. "Algorithm 232: Heap sort". Comm. ACM 7, 6
(June 1964), 347-348.
[11] ANDERSSON, A. and NILSSON, S. 1994. "A New Efficient
Radix Sort". In the Proceeding of the 35 Annual IEEE
Symposium on Foundation of Computer Science (1994),pp. 714-721.
[12] DAVIS, I.J. 1992. "A Fast Radix Sort". The computer journal 35, 6,
636-642.
[13] V.Estivill-Castro and D.Wood."A Survey of Adaptive Sorting
Algorithms", Computing Surveys, 24:441-476, 1992.
[14] T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C.
Stein."Introduction to Algorithms". MIT Press, Cambridge, MA, 2nd
edition, 2001.
[15] Sultanullah Jadoon, Salman Faiz, Salim ur Rehman, Hamid Jan
Design & Analysis of Optimized Selection Sort Algorithm,
IJEC-IJENS Volume 11 Issue 01, 2011.


K^^

/^
K^
^
n Calculated Time
of
SSA

Calculated Time of
Optimized SSA

Calculated Time of
Insertion Sort

n T(n) Old SS T(n) OSSA T(n)
InserT

S-ar putea să vă placă și