Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm gets its name because smaller elements "bubble" to the top of the list during each pass. Bubble sort has a time complexity of O(n^2) in the worst case, where n is the number of elements in the list. It is not considered very efficient for large datasets, especially when compared to more advanced sorting algorithms like quicksort or merge sort. However, it is easy to understand and implement, making it useful for educational purposes or small datasets.
Source Code |