Simplest sort algorithm

Simple and innefficient - HN / arxiv.org

This isn’t Bubble Sort

  • In bubble sort you see if two things are the wrong way round and it they are then you swap them. This does that (sort of) the “wrong way round”.
  • In Bubble Sort your indices are always i<j … here they aren’t.
  • In Bubble Sort you only ever compare adjacent items. Here you don’t.
  • This really, really isn’t Bubble Sort, unoptimised or other.
void sort() {
    for( int i = 0; i < N; i++)
        for( int j = 0; j < N; j++)
            if( id[i] < id[j])
                swap( i, j);
}

see also

caption

Written on October 14, 2022, Last update on March 15, 2025
sort