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 5 t h 5^{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.

0 1 2 3 4 5 6 7 8 9 3 4 6 7 8 2 5 9 0 1 3 6 7 8 4 2 5 9 0 1 6 8 3 7 4 2 5 9 0 1 3 6 8 7 4 2 5 9 0 1

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Geoff Pilling
Feb 3, 2017

After the fifth iteration the first five elements will be sorted and the last five will be just the way they were.

So it will be 3467825901 \boxed{3467825901}

Vijay Kumar
Feb 9, 2016

Sorry, I cannot get your solution... :(

Zeeshan Ali - 5 years, 4 months ago

Really it is 4 th iteration

Hasmik Garyaka - 3 years, 8 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...