News for hackers. Stuff that matters.
Re:Is this the simplest (and most surprising) sorting algori... by areyousure on Tuesday October 05, 2021 @05:08PM (#28765652)
> I use this algorithm to introduce sorting.

Do you have any (publicly-available) course materials that mention this algorithm? The OP mentions they were "unable to find any references to it", and I've been collecting references I find in this comment: https://news.ycombinator.com/item?id=28760986#28762275

> What’s non-intuitive or what makes the comparison in the wrong order?

In a sibling comment, 'ColinWright compares this algorithm to bubble sort, which has the comparison in the other direction. Another similar algorithm is this selection sort which differs by one character:

  for i = 1 to n do
    for j = i to n do
      if A[i] < A[j] then
        swap A[i] and A[j]
This also sorts the array, but in the opposite order. It's true that seen in the correct light, both of these algorithms can be seen to work, but it definitely confuses people. For example, these three answers on Math Stack Exchange and Stack Overflow are incorrect about the sorting order: https://math.stackexchange.com/a/876452 https://stackoverflow.com/a/61970459 https://stackoverflow.com/a/57118286

There are no comments on this comment yet.