OPTIMIZED-BUBBLE-SORT.JS


comparisons:
swaps:



The optimization comes from the fact that after each traversal of a bubble sort, the last swap always adds one element to an already sorted end of the array. This allows for each successive traversal to be shorter then the previous one. Because of this, some people think that bubble sort should be more appropriately called sinking sort.

sort.js
bubble-sort.js optimized-bubble-sort.js selection-sort.js
cocktail-sort.js optimized-cocktail-sort.js
odd-even-sort.js comb-sort.js quick-sort.js
gnome-sort.js optimized-gnome-sort.js
compare sort algorithms