Given this algorithm in pseudocode that sorts any array, how can I formulate a loop invariant that proves its correctness using induction and how do I find its time complexity ?
Input: array A[0 . . . n − 1]
i ← 0
while i < n do
if i = 0 or A[i] ≥ A[i − 1] then:
i ← i + 1
else
swap A[i] and A[i − 1]
i ← i − 1
Additionally I got a hint stating: Use the invariant "at the moment when the variable i gets incremented to a new value i = k for the first time, the first k elements of the array are sorted in increasing order".
Thank you in advance !