4 ms·
This is bubble sort https://en.m.wikipedia.org/wiki/Bubble_sort https://en.m.wikipedia.org/wiki/Bubble_sort This should be in the standard college level CS cl
by justicezyx 5y ago
This is bubble sort
https://en.m.wikipedia.org/wiki/Bubble_sort https://en.m.wikipedia.org/wiki/Bubble_sort
This should be in the standard college level CS classes.
Edit:
As mentioned elsewhere, this is not exactly same as the textbook bubble sort
When I wrote this, I am saying in the sense that each outer iteration "bubbles" up to its correct place, by swapping.
Thinking twice this also appears to just be a selection sort, as it indeed swaps in each iteration the smallest element
But overall, the algorithm is not surprising at all to me. It seems unusual indeed though.
- ColinWright 5y agoI suggest you read elsewhere in this discussion, where many people have claimed it is a Bubble Sort, and most have then changed their minds. Consider, a Bubble Sort (as documented in TAoCP, for one) only ever compares elements in adjacent locations, whereas this routine compares every location to every other location.
- jonsen 5y agoThen think trice. Selection sort gets its name from doing work to find, select, the overall smallest element. This algorithm just takes the element at position i and inserts it at the so far right place in the sorted subarray to the left of i. It's an inefficient (and somewhat obscure) variant of insertion sort.
- justicezyx 5y agoBut overall it's not surprising to me...