Bubble Sort
Bubble Sort
Data Structures
SORTING
Sorting is process of arranging the elements in a particular order. The
order may be ascending order or descending order. The advantage of
sorting is effective data accessing.
Begin
30 the
10 sort
5 by comparing
20 15first two elements
Compare A[0]
and A[1]. Since 30>10, interchange
10 30 5 20 15
Compare A[1]
10 5 30 20 15
and A[2]. Since 30>5, interchange Pass 1
10 5 20 30 15 Compare A[2]
and A[3]. Since 30>20, interchange
10 5 20 15 30
Compare A[3]
and A[4]. Since 30>15, interchange
10 5 20 15 30 Compare A[0] and A[1]. Since 10>5, interchange
Disadvantages:
1. It runs slowly and hence it is not efficient, because more efficient
sorting techniques are available.
2. Even if array is sorted, n-1 comparisons are required.
THANK YOU