113. Searching and Sorting-I

Question.4

An insertion sort is run on {20, 5, 12, 7, 3}. What does the array look like after 2 complete passes of the outer loop (i=1 and i=2)?

for (int i = 1; i < n; i++) {
   int temp = arr[i];
   int j = i - 1;
   while (j >= 0 && arr[j] > temp) {
       arr[j + 1] = arr[j];
       j--;
   }
   arr[j + 1] = temp;
}
Need Help? Refer to the Quick Guide below

Select Answer