3 ms·
For me, this is a lesson in the power of semantics. If one re-writes the if statement and switches the order, if A[j] > A[i] then I find the correctness of
by mirrorlake 5y ago
For me, this is a lesson in the power of semantics. If one re-writes the if statement and switches the order,
if A[j] > A[i] then
I find the correctness of the algorithm to be significantly more obvious.
It is true that i >= j, and sorted ascending values will have the property A[i] >= A[j].
It follows that swapping happens when the values are out of order, when
A[j] > A[i]