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 \(\text{Insertion Sort}\), given above, what is the modified version of the \(\text{Array}\), given below, after the \(5^{th}\) iteration ?

\[\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...