Ijirt142753 Paper
Ijirt142753 Paper
BUBBLE SORT
Priyanka kunjwal
Dronacharya College of Engineering
Haryana
When the list is already sorted (best-case), the
ABSTRACT:-Sorting algorithms provide a way complexity of bubble sort is only O (n). By contrast,
to arrange a series of numbers or letters in some most other algorithms, even those with better
predefined order based on some measurable average-case complexity, perform their entire
quantity in the numbers or letters. Thus we may sorting process on the set and thus are more
arrange a series of numbers according to their complex. However, not only does insertion sort have
values in an increasing order or we may arrange this mechanism too, but it also performs better on a
the letters according to decreasing order of their list that is substantially sorted (having a small
ASCII values using sorting. In this paper we will number of inversions).
describe a simple and easy to implement sorting
algorithm called Bubble Sort. Bubble sort should be avoided in the case of large
collections. It will not be efficient in the case of a
INTRODUCTION reverse-ordered collection
The only significant advantage that bubble sort has Now, the array is already sorted, but the algorithm
over most other implementations, even quicksort, does not know if it is completed. The algorithm
but not insertion sort, is that the ability to detect that needs one whole pass without any swap to know it
the list is sorted is efficiently built into the algorithm. is sorted.
Third Pass
for i = 1 to n-1 inclusive do if A[i-1] > A[i] then
(1 2 4 5 8) (1 2 4 5 8) (1 2 4 5 8) (1 2 4 5 8) swap(A[i-1], A[i])
(1 2 4 5 8) (1 2 4 5 8) (1 2 4 5 8) (1 2 4 5 8)
new n = i
IMPLEMENTATION
end if end for n = newn
procedure bubbleSort( A : list of sortable items ) n = for ( c = 0 ; c < n ; c++ ) printf("%d\n", array[c]);
length(A)
repeat return 0;
}
new n = 0
OUTPUT :
REFRENCES: