# data structure
Recall that the Insertion sort algorithm (for sorting an array A)
from low to high has the skeleton form:
for (i = 1; i < A.length; i++) {
details omitted
}
For i = 1 to 6, show how the contents of the array is rearranged
if at all) after each iteration of the for-loop.
(10 pts)
the original array A
A
6. 4. 7. 5. 2. 8. 3.
0 1 2 3 4 5 6
after i = 1
A
0 1 2 3 4 5 6
after i = 2
A
0 1 2 3 4 5 6
after i = 3
A
0 1 2 3 4 5 6
after i = 4
A
0 1 2 3 4 5 6
after i = 5
A
0 1 2 3 4 5 6
after i = 6
A
0 1 2 3 4 5 6
initially:
6 4 7 5 2 8 3
0 1 2 3 4 5 6
after i=1
4 6 7 5 2 8 3
0 1 2 3 4 5 6
after i=2(no change)
4 6 7 5 2 8 3
0 1 2 3 4 5 6
after i=3
4 5 6 7 2 8 3
0 1 2 3 4 5 6
after i=4
2 4 5 6 7 8 3
0 1 2 3 4 5 6
after i=5(no change)
2 4 5 6 7 8 3
0 1 2 3 4 5 6
after i=6
2 3 4 5 6 7 8
0 1 2 3 4 5 6
(NOTE:for any doubt in the solution just leave a comment else please press the like button)
Get Answers For Free
Most questions answered within 1 hours.