Question: Consider the following sorting algorithm, and answer the questions below static void sort(int[] array) { superSort (array, 0, array.length - 1); } static void
Consider the following sorting algorithm, and answer the questions below static void sort(int[] array) { superSort (array, 0, array.length - 1); } static void superSort(int [] array, int p, int q) { if (q p < 1) return; for (int i = p; i < q; i++) { if (array[i]> array[i+1]) { swap (array, i, i+1); // swap array[i] with array[i+1] in 0(1) time } } for (int i = q; i > p; i--) { if (array[i] < array[i-1]) { swap (array, i, i-1); // swap array[i] with array[i-1] in 0(1) time } } superSort (array, p+1, q-1); } Is superSort a stable sorting algorithm? If not, how could it be made stable? What is the running time of superSort on an already sorted array? Justify your answer. Write a recurrence relation to express the worst-case running time of superSort. Solve the recurrence relation.
Step by Step Solution
There are 3 Steps involved in it
The provided sorting algorithm superSort is a variation of the Bubble Sort algorithm Lets analyze it and address the questions one by one Stability of ... View full answer
Get step-by-step solutions from verified subject matter experts
