Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
156 views

Friends Sort Algorithm

dmslkc

Uploaded by

SahilYadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

Friends Sort Algorithm

dmslkc

Uploaded by

SahilYadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

A New Friends Sort Algorithm

Sardar Zafar Iqbal

Hina Gull

Abdul Wahab Muzaffar

Iqra University of science and


technology, Islamabad, Pakistan
zafar.iqbal38@gmail.com

National University of Science and


Technology Nust, H-11, Islamabad,
Pakistan
itshina_03@yahoo.com

Shaheed Zulfikar Ali Bhutto


Institute of Science and
Technologies (SZABIST),
Islamabad, Pakistan
wahab_muzffar2000@yahoo.com

Abstract Sorting algorithms and the sorting itself is an


important concept in computational field. In this research
study, we are proposing a unique sorting algorithm, based on
assuming the first value as smallest and comparing it with the
rest of the list and assuming the last value as biggest and
comparing it with the rest of the list. Running cost analysis and
its results obtained after implementation are provided in
graphical form with an objective to compare the efficiency of
the proposed technique with some existing well known
techniques of sorting.
I.

INTRODUCTION

Algorithms have a vital and key role in solving the


computational problems, informally an algorithm is a welldefined computational procedure that takes input and
produces output. Algorithm is a tool or a sequence of steps to
solve the computational problems [1]. Now what sorting
really is, sorting is the organization of data into a particular
increasing or decreasing order i.e. in ascending and
descending order. Data can be in numerical or character form.
There are a lot of sorting techniques, currently used in
industry and academia, to arrange the data of various forms
and from different areas.
The study in hand proposes a new sorting technique that
is tested and analyzed against previous sorting techniques to
provide its efficiency. Sorting is of considerable importance
as the human is possessed in keeping the ordered
information/knowledge. To search the information
efficiently the arrangement of data is very important. To
facilitate the human, computers consume a substantial time
in ordering the data [2]. Sorting is the reorganizing of given
items on the basis of some well defined ordering rules [3].
The computational problems always have a cumbersome
effect on the researchers on one hand and open the
opportunities for them on the other hand. The ultimate
intention of so much sorting techniques is the cost and
complexity reduction of the algorithms. In this research
paper, we propose a new sorting technique; derive its
algorithm and compare it with some well known techniques
(bubble sort, cocktail sort, selection sort and insertion sort),
already in the market. This sort is clearly efficient than
bubble sort and cocktail sort and almost equal in efficiency
with selection sort for the small data and less efficient for
larger data All the analysis and graphs have been provided
for the researchers and scientists to check its efficiency.

_____________________________
978-1-4244-4520-2/09/$25.00 2009 IEEE



II.

A BRIEF REVIEW OF EXISTING SORTING


ALGORITHMS

A number of sorting techniques are currently used in the


field of computer science. This section will briefly discuss
some of the trendy sorting techniques among them. These
are following:
A. Bubble Sort
Bubble sort is the pioneer among all the sorting
techniques, the simplest and popular one in fact. It takes a
list compare the two items at a time and swaps them if they
are not sorted, repeat the steps until the one of the compared
item reaches its exact location in that list, these whole steps
continue till no swapping is needed more and this is the time
when sorting is completed. The name of this algorithm
comes from the tactic the smaller elements bubble to the
top of the list [4]. For the list of 100 items, bubble sort makes
10000 comparisons to sort the list, it is thrifty and is
inefficient as compared to todays sorting algorithms. If we
have a sorted list and apply bubble sort it shows a behavior
of O(n). Average and worst case complexity of bubble sort is
O(n).
B. Cocktail Sort
Cocktail sort, also known as shaker sort, bidirectional
bubble sort, cocktail shaker sort (this also refers to a variant
of (selection sort), ripple sort, shuttle sort or happy hour sort,
is a variation of bubble sort that is both a stable sorting
algorithm and a comparison sort [5]. The cocktail sort is
different from bubble sort, as it sorts the list from both
directions. Cocktail sort is a bit complex than bubble sort in
implementation. It is simple in nature and solves the problem
with turtles like in bubble sort. The average an the worst
case complexity of cocktail sort is equal to bubble sort i.e.
O(n).
C. Selection Sort
Selection sort is another well known sorting technique
that scans the list/array to find the smallest item, puts it at the
first location in the list/array, and then scans the list for the
second smallest item, puts it in the second location, then
third smallest and so forth until reaches the largest item in
the list putting it at the last location of the list. It has O(n)
complexity, inefficient for the larger lists or arrays. For large
lists its performance is worst than that of insertion sort. In

certain situations, it has a prominent efficiency than some


other convoluted algorithms. The number of passes, of the
selection sort for a given list, is equal to the number of
elements in that list [6]. The number of interchanges and
assignments depends on the original order of the items in the
list/array, but the sum of these operations does not exceed a
factor of n [7].
D. Insertion Sort
Another renowned and simple technique of sorting is
insertion sort. Insertion sort, an efficient sorting technique,
selects one element in every pass and inserts it to the original
location in a new list. It is highly efficient on small lists and
is very simple and easy to implement. The worst case
complexity of insertion sort is also O(n). The insertion sort
algorithm is a very slow algorithm when list is very large [8].
E. Quick Sort
Quick sort is another well-known sorting algorithm and
base on divide-and-conquer paradigm. Its worst-case running
time is (n) having a list of n items. In spite of slow worstcase running time, quick sort is often the best practical
choice for sorting the lists because it is extremely efficient on
the average running time i.e. (nlogn) [9]. In most realworld data it is possible to make design choices which
minimize the probability of requiring quadratic time [10].
F. Bucket Sort
Bucket sort, or bin sort, works by partitioning an array
into a number of buckets. Each bucket is then sorted
individually, either using a different sorting algorithm, or by
recursively applying the bucket sorting algorithm [11]. It is a
cousin of radix sort in the most to least significant digit
flavor. Since bucket sort is not a comparison sort, the
(nlogn) lower bound is inapplicable. The computational
complexity estimates involve the number of buckets [12].
III. FRIENDS SORT ALGORITHM
Friends sort is based on the idea of selection sort, it
assume the first item of the list as the smallest item compare
it with next items if required swap them else compare it with
the next item. Then assume the last item of the list as the
biggest and compare it with the previous item of that list in
the same manner as in first one. So in one pass two items in
the list are in their exact position in the list. The steps of the
proposed Friends sort algorithm are as follows:
1. Take 1st element of the list and compare it with next
element
If required swap the two elements.
else
go to step 2.
2. Take Last Element and compare it with Second last
element
If required
Swap the two elements.
3. Iteratively compare this 1st and Last Element with
the whole list and swap wherever required.
4. Increment the pointer and move to Next Element and
compare it with the whole list.

5.
6.
7.
8.

Take the middle element of the list.


Compare it with 1st and Last Element.
If required swap the two Elements.
In short, in one pass it will put two Elements in their
exact locations.
IV.

ALGORITHM:PSEUDO CODE

FRIENDSSORT(List)
First:= 0
Last:= LENGTH[LIST]
Mid:= LENGTH[LIST]/2
WHILE k < LAST/2 || j> LAST/2
l:=k+1
m=j-1
WHILE l< LAST-1 || m>FIRST
If (LIST[k] > LIST [l])
LIST[k]=LIST[l]
LIST[l]=LIST[k]
If (LIST[j] < LIST [m])
LIST[j]=LIST[m]
LIST[m]=LIST[j]
l++
m- If (LIST[mid] < LIST [k])
LIST[mid]=LIST[k]
LIST[k]=LIST[mid]
If (LIST[mid] > LIST [j])
LIST[mid]=LIST[j]
LIST[j]=LIST[mid]
K++
J--;
V.

RUNNING COST ANALYSIS

The main structure of the algorithm depicts that there is


an outer main loop within which there lies another loop. The
outer loop will run half the number of times, of the elements
of the list and inner loop will make its way n-1 times in
worst case analysis, i.e. if the whole list to be sorted is in
reverse order (descending while ascending is needed or
ascending when descending is needed). By keen observing it
the worst case running cost of algorithm is calculated to be
O(n2).
The behavior of the algorithm in the best case will be
O(n), depicting that the elements in the list are in sorted form
(descending or ascending whatever needed).
Similarly the average case of the running cost will be
O(n2) depending upon the elements in the list.
VI.

COMPARISON OF FRIENDS SORT WITH


VARIOUS EXISTING SORTING ALGORITHM

To gap efficiency of Friends sort performance, it was


implemented along with other existing famous sorting
algorithms. By taking lists of various sizes, items were
generated using a uniform random number generator with
values ranging from 1 to 10,000. Running times were noted
down. The plots are given below.



A. Comparison with Bubble Sort Graph:


In the above graph, at x-axis we have placed number of
elements in the list to be sorted and at y-axis we have placed
the time taken by program for execution in milliseconds. It
can be seen clearly that up to 25000 elements the difference
is not much but when the size starts increasing, execution
time of bubble sort also increases rapidly while Friends sort
and much more better performance that is obvious from the
graph.

B. Comparison with Cocktail Sort Graph:


The above graph same as that of bubble sort that at x-axis
are the numbers of items and along y-axis are the execution
times in milliseconds. Like bubble sort the change in
execution times is almost same but performance difference
starts emerging when we move to larger lists.

D. Comparison with Insertions Sort Graph:


Above graph depicts the performance difference of
Insertion and the Friends sort. Along x-axis is the number of
items in the input list while along y is the execution times.
Friends sort is almost equal up to 25000 elements but after
that its efficiency degrades.
VII. CONCLUSIONS
By analyzing the graphs above, it can be easily examined
that Friends Sort is clearly efficient than some well known
sorts (Bubble sort, Cocktail sort), equally efficient with
selection sort and insertion sort for the small data and less
efficient for larger data, although it is less efficient than the
most efficient algorithms like Merge sort and Quick sort. In
future, we are foreseeing to come up with a new sorting
technique, which hopefully will be more efficient. Overall
this analysis shows that friends sort is very efficient for small
number items in a list, so it will show high efficiency for
smaller list of up to 35000 elements.

ACKNOWLEDGMENT
We acknowledge the support and contribution from our
loving and caring families and friends in continuing the
education and research. With their moral and financial
support, we are in higher education, which encourages us to
write this research for the ease of human kind. Thank you all.
REFERENCES
[1]

[2]
[3]

C. Comparison with Selection Sort Graph:


Above graph depicts the performance difference of
Selection and the Friends sort. Along x-axis is the number of
items in the input list while along y is the execution times.
Friends sort is almost equal up to 35000 elements but after
that its efficiency degrades.

[4]

[5]
[6]

[7]



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 1.1:
Algorithms, pp.56.
D. A. Bailey, Java Structure:Data Structure in Java for Principled
Programmer, 2nd ed. McGraw-Hill, 2003.
R. Sedgewick, Algorithms in C++. Reading, Massachusetts: AddisonWesley, 1992.
Donald Knuth. The Art of ComputerProgramming, Volume 3: Sorting
and Searching, Third Edition. Addison-Wesley, 1997. ISBN 0-20189685-0. pp. 106110 of section 5.2.2: Sorting by Exchanging.
http://en.wikipedia.org/wiki/Cocktail_sort
Donald Knuth. The Art of Computer Programming, Volume 3:
Sorting and Searching, Third Edition. Addison-Wesley, 1997. ISBN
0-201-89685-0., pp. 138141, of Section 5.2.3: Sorting by Selection.
Seymour
Lipschutz.
Theory
and
Problems
of
Data
Structures,Schaums Outline Series: International Edition, McGraw-

Hill, 1986. ISBN 0-07-099130-8., pp. 324325, of Section 9.4:


Selection Sort.
[8] Seymour
Lipschutz.
Theory
and
Problems
of
Data
Structures,Schaums Outline Series: International Edition, McGrawHill, 1986. ISBN 0-07-099130-8., pp. 322323, of Section 9.3:
Insertion Sort.
[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
7.1:Quicksort, pp.145149.
[10] Hoare, C. A. R. "Partition: Algorithm 63," "Quicksort: Algorithm
64," and "Find: Algorithm 65." Comm. ACM 4(7), 321-322, 1961.
[11] 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 8.4:
Bucket sort, pp.174177.
[12] Butt, W.H. Javed, M.Y. , A new Relative sort algorithm based on
arithmetic mean value, in IEEE Multitopic Conference, karachi, 2008.
pp.
374-378.
Available:
http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4777766.



You might also like