INPUT: array A[0..n-1]
1 for i := 1 to n-1
2 v := A[i]
3 j := i - 1
4 while j ≥ 0 AND A[j] > v
5 A[j+1] := A[j]
6 j := j - 1
7 A[j+1] := v
Trace this algorithm for the input [89 45 68 90 29] and write down the following information just before executing Line 7 on each pass:
Design a decrease-and-conquer algorithm to sort the array. Use the following invariant:
After k steps, the largest k numbers are in their correct positions.