Bubble sort is a simple sorting algorithm that compares adjacent elements and swaps them if they are not in order. It has a worst-case and average time complexity of O(n2) where n is the number of items, making it inefficient for large data sets. The algorithm makes multiple passes through the array, swapping adjacent elements that are out of order until the array is fully sorted. It is one of the simplest sorting algorithms to implement but does not perform well for large data sets due to its quadratic time complexity.
SUBMITTED BY :
Name: Saiful Islam
Institute: Green University Of Bd
ID : 162-015-022
Batch : 162
1
2.
What is bubblesort :
Bubble short is A simple sorting algorithm. This sorting algorithm is
comparison based algorithm in which each pair of adjacent elements is
compared and elements are swapped if they are not in order . this
algorithm is not suitable for large data sets as its average and worst case
complexity are of 0(n2) where n are no. Of items.
2
3.
How bubble sortworks?
We take an unsorted array for our example. Bubble sort take 0(n2) time so
we’re keeping short and precise.
3
4.
Sorting :
Inthis case, value 33 is greater than 14, so it is already in sorted locations.
Next, we compare 33 with 27
Bubble sort starts with very first two elements, comparing them to check
which one is greater.
4
5.
Sorting :
Thenew array should look like this -
We find that 27 is smaller than 33 and these two values must be swapped.
5
6.
Sorting :
Nextwe compare 33 and 35. We find that both are in already sorted
position.
Then we move to next two values, 35 and 10.
We know than 10 is smaller 35. Hence they are not sorted.
6
7.
Sorting second time:
First sort
Second sort
Third sort
Fourth sort
Now we should look into same practical aspects of bubble sort.
7
8.
Advantages :
Itdoes not deal well with a list containing a huge number of
items.
More than the number of comparisons.
The code become complex for large amount of data.
Disadvantages :
Bubble sort is one of the easiest sort algorithm.
It is easy to implement.
Elements are swapped in place, not use extra array.
It is stable and fast.
8