Task :
Python program to for Bubble Sort
Time Complexity of Bubble Sort
Best Case | O(n) |
Average Case | O(n2) |
Worst Case | O(n2) |
Algorithm:
Given a list L of n elements with values or records L0, L1, …, Ln-1, bubble sort is applied to sort the list L.
- Compare first two elements L0, L1 in the list.
- if L1 < L0, swap those elements and continue with next 2 elements.
- Repeat the same step until whole the list is sorted, so no more swaps are possible.
- Return the final sorted list.
No comments