Bubble
Bubble Sort is a simple sorting algorithm that repeatedly steps through a list of elements, compares adjacent elements and swaps them if they are in the wrong order.
The algorithm gets its name from the way smaller elements "bubble" to the top of the list with each iteration.
pseudocode:
Here are the basic steps of the Bubble Sort algorithm:
Starting at the beginning of the list, compare each pair of adjacent elements.
If the elements are in the wrong order (e.g., the second element is smaller than the first), swap them.
Continue iterating through the list until no more swaps are needed (i.e., the list is sorted).
The list is now sorted. Bubble Sort has a time complexity of O(n^2), making it relatively slow for large datasets.
However, it is easy to understand and implement, and can be useful for small datasets or as a starting point for more optimized sorting algorithms.
Implementation in JavaScript
Output
Last updated