<p><span style="color: #008000;"><strong>Bubble sort</strong></span> algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the 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 Ο(n<sup>2</sup>) where <b>n</b> is the number of items.</p>
<!-- WP QUADS Content Ad Plugin v. 2.0.98.1 -->
<div class="quads-location quads-ad2" id="quads-ad2" style="float:none;margin:0px;">

</div>

<pre style="padding-left: 60px;"><strong><code>public class Sort {

public static void bubbleSort(int arr[]) {
int temp;
for(int i=0;i<;arr.length-1;i++) 
 {
 for (int j = 0; j <; (arr.length - 1) - i; j++) 
 { 
 if (arr[j] >; arr[j + 1]) {
 temp = arr[j];
 arr[j] = arr[j + 1];
 arr[j + 1] = temp; }
 }
 }
 }

public static void main(String[] strr) {
int arr[] = {23,67,90,12,3,87,34,23,78,56};
System.out.println(" Before sorting");
for(int j=0;j<;=arr.length-1;j++)
{
System.out.print(" "+arr[j]);
}
bubbleSort(arr);
System.out.println("\nAfter Sorting");
for(int j=0;j<;=arr.length-1;j++)
{
System.out.print(" "+arr[j]);
}
}
}</code></strong></pre>
<h4><span style="color: #000080;">output:</span></h4>
<p><strong><span style="color: #0000ff;">Before sorting</span></strong><br />
<strong><span style="color: #0000ff;">23 67 90 12 3 87 34 23 78 56</span></strong><br />
<strong><span style="color: #0000ff;">After Sorting</span></strong><br />
<strong><span style="color: #0000ff;">3 12 23 23 34 56 67 78 87 90</span></strong></p>
<h4><span style="color: #000080;"><strong>Time Complexity:</strong> </span></h4>
<p>The complexity of bubble sort is <span style="color: #008000;"><strong>Ο(n<sup>2</sup>)</strong></span> in both worst and average cases, because the entire array needs to be iterated for every element.

