Hacker News new | ask | show | jobs
by asrp 1452 days ago
After each outer loop iteration, A[:i] (the array up to i) is in ascending order with the max of A at A[i].

This is true the first iteration since max(A) is eventually swapped to A[1]. This is true in subsequent iterations since during the ith iteration, it inserts the next element, initially at A[i], into A[:i-1] and shift everything up with swaps with A[i] so A[:i] is sorted, with the max of A moved to A[i]. After that no more swaps happen in the ith iteration since A[i] contains the max of A.