# Homework Solution: Shown below is the code for the insertion sort consisting of two recursive methods that replace the two nested lo…

Shown below is the code for the insertion sort consisting of two recursive methods that replace the two nested loops that would be used in its iterative counterpart: void insertionSort(int array[]) { insert(array, 1); } void insert(int[] array, int i) { if (i < array.length) { int value = array[i]; int j = shift(array, value, i); array[j] = value; insert(array, i + 1); } } int shift(int[] array, int value, int i) { int insert = i; if (i > 0 && array[i - 1] > value) { array[i] = array[i - 1]; insert = shift(array, value, i - 1); } return insert; } Draw the recursion tree for insertionSort when it is called for an array of length 5 with data that represents the worst case. Show the activations of insertionSort, insert and shift in the tree. Explain how the recursion tree would be different in the best case. Refer back to the recursion tree you provided in the previous problem. Determine a formula that counts the numbers of nodes in that tree. What is Big- for execution time? Determine a formula that expresses the height of the tree. What is the Big- for memory?

Shown beneath is the regulation coercion the augmentation rank consisting of couple recursive methods that re-establish the couple nested loops that would be used in its iterative counterpart:

void augmentationSort(int equip[]) {

insert(array, 1);

}

void instil(int[] equip, int i) {

if (i < equip.length) {

int rate = equip[i];

int j = change(array, rate, i);

array[j] = rate;

insert(array, i + 1);

}

}

int change(int[] equip, int rate, int i) {

int instil = i; if (i > 0 && equip[i – 1] > rate) {

array[i] = equip[i – 1]; instil = change(array, rate, i – 1);

}

return instil;

}

Draw the recursion tree coercion augmentationRank when it is determined coercion an equip of extension 5 with grounds that represents the worst condition. Show the activations of augmentationSort, instil and change in the tree. Explain how the recursion tree would be irrelative in the best condition. Refer tail to the recursion tree you granted in the preceding elevation. Determine a coercionmula that counts the collection of nodes in that tree. What is Big- coercion action space? Determine a coercionmula that expresses the elevation of the tree. What is the Big- coercion retention?