![selection sort vs bubble sort graph selection sort vs bubble sort graph](http://clweb.csa.iisc.ac.in/pradeep/Output/fast.jpg)
Select sort just notes the new boundary value (min for an ascending sort, max for descending) and then swaps it out at the end of the pass. You will then graph this data using the gnuplot graphing program which will. The answer, based purely on examination of my own and other implementations, is that bubble sort does a value swap (read, write, write) on EVERY SINGLE COMPARISON HIT. Below is the pseudocode for this algorithm to sort the elements of an array arr in ascending order. It is a stable as well as an in-place algorithm as it does not require extra storage area. Select sort can't be helped that way, so why would it outperform? Both are weak in general use - O(n^2) - so why isn't the one that can at least be marginally improved better? Bubble Sort is most often used to provide an insight into the sorting algorithms due to its simplicity.
![selection sort vs bubble sort graph selection sort vs bubble sort graph](https://www.titrias.com/files/2015/08/Untitled.png)
The question initially had me puzzled since bubble sort can be optimized by early termination of the outer loop after a sub-array (or linked list, etc) pass that fails to perform a value swap. Like bubble sort, I found this counter-intuitive because you. We now have a sorted list of size 2, and N -2 unsorted elements. Take the first unsorted item (element 2) and insert it into the sorted list, moving elements as necessary. While the insertion, selection, and shell sorts also have O(n2). Start with a sorted list of 1 element on the left, and N-1 unsorted items on the right. I can't seem to find a satisfying solution to this question here or elsewhere, though Senthil's link is headed in the right direction. As the graph pretty plainly shows, the bubble sort is grossly inefficient, and the shell. And, Wikipedia on bubble sort (emphasis added):