Just follow the logic

1
2
3
4
5
6
7
8
9
for i = 1 to length(A) - 1
    x = A[i]
    j = i - 1
    while j >= 0 and A[j] > x
        A[j+1] = A[j]
        j = j - 1
    end while
    A[j+1] = x
end for

Following the algorithm of Insertion Sort\text{Insertion Sort}, given above, what is the modified version of the Array\text{Array}, given below, after the 5th5^{th} iteration ?

8 6 3 7 4 2 5 9 0 1 \huge{\text{8 6 3 7 4 2 5 9 0 1 }}

Hint: You can either have a dry-run or just follow the logic.

×

Problem Loading...

Note Loading...

Set Loading...