Professional Documents
Culture Documents
Galgotias University: CAT-3 Report File Submission On
Galgotias University: CAT-3 Report File Submission On
1. INTRODUCTION.
2. ALGORITHM.
3. WORKING OF BUBBLE SORT ALGORITHM.
4. FIRST, SECOND, THIRD, FOURTH PASS.
5. BUBBLE SORT ALGORITHM COMPLEXITY.
(TIME AND SPACE COMPLEXITY).
6. OPTIMIZED BUBBLE SORT ALGORITHM.
7. CONCLUSION.
ALGORITHM.
In the algorithm given below, suppose arr is an
array of n elements. The assumed swap function in
the algorithm will swap the values of given array
elements.
1.begin BubbleSort(arr)
2. for all array elements
3. if arr[i] > arr[i+1]
4. swap(arr[i], arr[i+1])
5. end if
6. end for
7. return arr
8.end BubbleSort
First Pass
Stable YES
o The space complexity of bubble sort is O(1). It
is because, in bubble sort, an extra variable is
required for swapping.
o The space complexity of optimized bubble sort
is O(2). It is because two extra variables are
required in optimized bubble sort.
Now, let's discuss the optimized bubble sort
algorithm.
Conclusion
Bubble Sorting is a very simple algorithm and easy to
understand. This might even be the first approach that
would have come to your mind when you were
introduced to the concept of sorting while learning to
code. One of the disadvantages of this algorithm is
that it is very slow due to O(n). Conclusion Bubble sort
is the simplest sorting method. It traverses the entire
array and bubble pops the numbers which helps in
swapping and bringing the array in correct sequence.
It compares two adjacent numbers and pops those as
and when they are not in the expected order.