I would regard this as an (inefficient) implementation of insertion sort, except for the first iteration of the outer loop: this iteration will put the greatest value at index 0. But from then onwards, it operates as insertion sort, always moving the next value into the sorted left-partition of the list.
Details
In the first iteration of the outer loop the greatest value will be swapped to index 0. This should be clear: the value at index 0 is swapped when a greater value is encountered, and so all values are compared with it, guaranteeing the greatest value will end up there. If you wish you could interpret this as one iteration of selection sort in descending order.
From the second iteration onwards this really is insertion sort:
As in the first iteration, the greatest value will be swapped into the current index i
. But this time we know that the greatest value was sitting at the previous index, so when j==i-1
that swap will occur. That also means that when j > i
no swaps will happen anymore, and so the values at the right of index i
will not change -- they remain as they were right after the first iteration of the outer loop.
Secondly, the values at the left of index i
will remain sorted -- this is an invariant of the outer loop. We can prove this by induction. We know it is true after the first iteration, and as the inductive step we can reason as follows:
The value originally at index i
will be swapped backwards as soon as arr[j]
is a greater value, so that all up until arr[j]
is sorted correctly, and the new value at arr[i]
is greater than that. Such swaps will keep occurring as j
increases, and ultimately, at j==i-1
, a last swap will occur. At every swap, the sort order up to (and including) index j
is guaranteed until this last swap occurs and j
becomes equal to i
. At that moment the values up to index i
(including it) are in sorted order.
This practically means that from the second iteration onward, the value at index i
is "rotated" into the sorted partition of the list (at the left of index i
). At the end, the sorted partition is the whole list.