Analysis of Bubble Sort Time Complexity.
Analysis
of Bubble Sort Time Complexity. Bubble sort worst case time complexity is O(n^2), best case
is O(n) and average case time complexity is O(n^2). Bubble Sort Java
Program.
In this post we will see Bubble sort java program, How Bubble sort works in Java, Bubble sort Algorithm in java and Sorting array using Bubble sort in Java.
Lets understand what is the input and the expected output.
Time Complexity of Bubble Sort Algorithm.
- Time complexity of Bubble sort in Worst Case is O(N^2), which makes it quite inefficient for sorting large data volumes. O(N^2) because it sorts only one item in each iteration and in each iteration it has to compare n-i elements.
- Time complexity of Bubble sort in Best Case is O(N). When the given data set is already sorted, in that case bubble sort can identify it in one single iteration hence O(N). It means while iterating, from i=0 till arr.length, if there is no swapping required, then the array is already sorted and stop there.
- Bubble sort can identify when the list is sorted and can stop early.
- Bubble sort is efficient for (quite) small data sets.
- It is Stable sort; i.e., does not change the relative order of elements with equal keys.It takes O(1) extra space.