The insertion-sort algorithm provides an alternative to the selection-sort algorithm for sorting something like a hand of

Question:

The insertion-sort algorithm provides an alternative to the selection-sort algorithm for sorting something like a hand of cards, where there is a small number of items (about 20 or less). It’s more efficient than selection sort if the array is only slightly out of order, but it’s relatively inefficient for large numbers of items. The following code implements a descending insertion-sort algorithm:

1 2 3 4 5 6989 7 10 11 12 13 14 15 16 public static void insertion Sort(int[] cards) { int pick; int j; for

Note 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:

InsertionSort line# (cards) I J 1 Sort arr1 pick length 5 0 3 arr1 1 2 26 39 9 45 4

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: