Bubble sort
Bubble sort is a very simple sorting algorithm. It is not commonly used because it is inefficient and slower than many other sorting algorithms.
However, it is a great sorting algorithm to learn for beginners.
It is a stable, in-place, comparison-based sorting algorithm.
To see how this algorithm works in details please watch the video on my youtube channel.
Time complexity :
Worst Case: О(n2)
Average Case: О(n2)
Best Case: О(n2)
📢Recommended: Please watch the video first of all. Try to understand the algorithm and the idea behind it and then try to implement the algorithm on your own first, before looking at the code down below.
🎁code:
output:
Before sorting:
[100, 10, 44, 2, 16, 1]
After sorting:
[1, 2, 10, 16, 44, 100]
Comments
Post a Comment