Really fun video. There's a small mistake in the pseudocode in the video, where the indices are compared instead of the elements. Regardless, when he goes to demonstrate it he does compare the actual element values.
In that demonstration it seems like you can divide each pass into two parts: where i comes before j, and where i comes after j. It seems that only the pass where i comes after j (which is the first half) actually does something useful, the other half seems to sort it the opposite way, which then gets undone with the possibility to change it back being removed (since "i" has moved on permanently).
I suspect you could leave that second half out without changing the result. But if you only consider that first part (of sorting it "oppositely" to the comparison until the other index), it becomes equivalent to bubble sort.
It took me a while, but the surprising part is that the inner loop goes back to the first element again, unlike bubble sort which never revisits the outer loop's elements. So, at some point you'll compare element 3 with element 1, and swap so that 3 is smaller than 1, which is surprising.
It's not, but it's conceptually very similar at first glance.
One important thing to note is that bubble sort places one element in the correct position each pass and then *stops looking at that position ever again*.
This algorithm looks at all N elements every pass.
Others have shared a bunch of great videos and writeups. Without reading them, my initial assumption is that this builds things bottom up (such that after the first pass, the element in position 0 is guaranteed to be the lowest element) and that despite it being compared again and again, it's essentially placing one element each pass, but I could be wrong.
Look at it more carefully. Just reading the code, you'd think someone got confused between insertion sort and bubble sort and made a mashup that can't possibly work. But it still does.
"Two versions of this algorithm exist: a deterministic version that enumerates all permutations until it hits a sorted one, and a randomized version that randomly permutes its input and checks whether it is sorted.
An analogy for the working of the latter version is to sort a deck of cards by throwing the deck into the air, picking the cards up at random, and repeating the process until the deck is sorted. In a worst-case scenario with this version, the random source is of low quality and happens to make the sorted permutation unlikely to occur."