Bilateral Selection Sort
Bilateral Selection Sort
Bilateral Selection Sort
http://doi.org/10.22214/ijraset.2020.7042
International Journal for Research in Applied Science & Engineering Technology (IJRASET)
ISSN: 2321-9653; IC Value: 45.98; SJ Impact Factor: 7.429
Volume 8 Issue VII July 2020- Available at www.ijraset.com
Abstract: In today’s digital world data is playing wide role and the amount of the is growing drastically. Sorting of data makes it
easier to handle data in large scale. There are many sorting techniques are available for sorting of data. Some of these techniques
are Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, Merge Sort, Heap Sort, etc. Some sorting techniques work faster for
small amount of data and some work faster for large amount of data.
I. INTRODUCTION
Sorting is process of arranging list of elements to ascending and descending order Information/data growth in digital world leads to
rapid development of sorting algorithm. The sorting algorithms with increased performance and decreased complexity attracts
researcher’s attention towards sorting techniques. Selection sort algorithm is used to sort elements based on min elements for
ascending sort and max element for descending sort. On other hand bilateral sorting implies to sort elements by finding smallest and
largest element at same time and swapping with start and end position of unsorted array.
A. Algorithm
1) Step 1: Set MIN AND MAX to location 0
2) Step 2: Set leftshrink = i and rightshrink= n
3) Step 3: Search the minimum and maximum element in the list
4) Step 4: Swap the minimum with List[leftshrink] and Maximum with List[rightshrink]
5) Step 5: Increment min point and decrement max point
6) Step 6: Decrement rightshrink
7) Step 7: Repeat until List/2
B. Pseudo code
START PROCEDURE
list: Array of elements
n: Size of list
rightshrink: n-1
FOR i = 0 till n/2
min = i
max = i
FOR leftshrink = i till rightshrink
IF list[leftshrink] > max
THEN max = list[ leftshrink ] AND getindexmax = leftshrink
ELSE IF list [leftshrink] < min
THEN min = list [ leftshrink ] AND getindexmin = leftshrink
END-FOR
Swap in list (list[ i ] with list[getindexmin])
IF list[ getindexmax ] == max
Swap in list ( list[ rightshrink ] with list[getindexmin ])
ELSE
Swap in list ( list[ rightshrink ] with list [ getindexmax ])
--rightshrink
END-FOR
END PROCEDURE
C. Code
public void BSS(int[] arr)
{
int n = arr.length;
int rightshrink=n-1;
int temp=0,min,max,getindexmin,getindexmax;
for(int i = 0;i < n/2; i++) {
min = max = arr[i];
getindexmin = getindexmax = i;
for (int leftshrink = i; leftshrink <= rightshrink; leftshrink++){
if (arr[leftshrink] > max){
max = arr[leftshrink];
getindexmax = leftshrink;
}
else if (arr[leftshrink] < min){
min = arr[leftshrink];
getindexmin = leftshrink;
}
}
temp = arr[i];
arr[i]=arr[getindexmin];
arr[getindexmin]=temp;
if (arr[getindexmin] == max) {
temp = arr[rightshrink];
arr[rightshrink] =arr[getindexmin];
arr[getindexmin] =temp;
}
else {
temp = arr[rightshrink];
arr[rightshrink] =arr[getindexmax];
arr[getindexmax] =temp;
}
--rightshrink;
}
}
IV. BREAK DOWN ANALYSIS OF SELECTION SORT WITH BILATERAL SELECTION SORT
BSS Sort works with same structure as Selection sort follows. But the iterations are dynamically calculated on the size of
data which needs to be sort. Selection Sort has the complexity of O(n2) for the best case , worst case and average case.
BSS complexity is been derived (n/2)*(n/2) = O(n2).
Following is the breakdown for every iteration for better understanding.
Inner Loop 5 3
Outer Loop 1 2 3 4 5
Inner Loop 5 4 3 2 1
Total : Outer Loop total(5) x (Total Inner
Loop(5+4+3+2+1)) = 20
Outer Loop 1 2 3
Inner Loop 6 4 2
Total : Outer Loop total(3) x (Total Inner Loop(6+4+2)) =
15
Outer Loop 1 2 3 4 5 6
Inner Loop 6 5 4 3 2 1
Total : Outer Loop total(6) x (Total Inner
Loop(6+5+4+3+2+1)) = 27
Inner Loop 8 6 4 2
Total : Outer Loop total(4) x (Total Inner Loop(8+6+4+2))
= 24
Outer Loop 1 2 3 4 5 6 7 8
Inner Loop 8 7 6 5 4 3 2 1
Total : Outer Loop total(8) x (Total Inner
Loop(8+7+6+5+4+3+2+1)) = 44
1000000
0
0 100 200 300 400 500 600
As per the understanding from the breakdown analysis we find the pattern of total iteration between both the selection sort and bilateral
selection sort as follow:
No of data 5 6 7 8 9 10 11 12 13 14 15
Selection 1 2 2 10 11
Sort 4 0 7 35 44 54 65 77 90 4 9
Bilateral
Selection 1 1 1
Sort 0 5 8 24 28 35 40 48 54 63 70
This data shows the iterations of selection sort with respect to bilateral selection sort and number of iterations in bilateral
sort is lesser which makes it faster than selection sort.
Therefore the comparison chart of Bilateral Selection Sort and Selection Sort is derived where it results to Bilateral Selection Sort
Algorithm works faster compare to Selection Sort Algorithm in sorting data.
VI. CONCLUSION
Logic of Bilateral Selection Sort is based on the Selection sort algorithm. The main difference in Selection sort and Bilateral Selection
Sort is that the Selection sort 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 places
those at their appropriate locations then during second iteration it sorts the second largest and second smallest elements from the
remaining array data and places those in their appropriate locations in the array. Similarly, it sorts rest of the data elements and puts
those in their proper positions. Bilateral Selection Sort sorts the data in half iterations as compared to selection sort technique. The
improvement is also of the order.
REFERENCE
[1] Sultanullah Jadoon, Salman Faiz, Prof. Dr. Salim ur Rehman, Prof. Hamid Jan, Design and Analysis of Optimized SelectionSort Algorithm.
[2] Kirti Kaushik, Jyoti Yadav, Kriti Bhatia Design and Analysis of Optimized Selection Sort Algorithm.
[3] Holcers Balazs, Introduction to Sorting Algorithms: A guide to implement sorting algorithms on a step by step basis.