The Insertion Sort algorithm provides an alternative to the Selection Sort algorithm for sorting small numbers of items (of order 20 or less). It’s not quite as efficient as Selection Sort for arrays, but it is slightly more efficient for other kinds of data collections. The following code implements the Insertion Sort algorithm:
10 public static void insertionSort(int[] list)11 {12 int temp;13 int j;1415 for (int i=1; i0 && tempNote that the scope of the j count variable extends beyond the scope of the for loop in which it’s used. Assume that an array of int has been instantiated and the insertionSort method has been called with a reference to this array passed in as a parameter. Trace the execution of this method, using the following header and initial entries:
Sort
line#
insertionSort
arr1
(list)
i
j
temp
length
0
1
2
3
4
3333
1234
2222
1000
10
arr1
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.