Question: *JAVA ONLY* Defend all answers based on specific references to the code. Do not count return statements or initialization of method arguments. You are strongly
*JAVA ONLY*
Defend all answers based on specific references to the code. Do not count return statements or initialization of method arguments. You are strongly encouraged to walk through algorithms in the debugger and to add statement-counting code to given methods to test and refine your analysis. All growth functions must be in simplified t(n) = ____ format and order must be presented in proper big-O notation.
/** * Take an int[] and reorganize it so they are in ascending order. * @param array ints that need to be ordered */ public static void sortIt(int[] array) { for (int next = 1; next < array.length; next++) { int value = array[next]; int index = next; while (index > 0 && value < array[index - 1]) { array[index] = array[index - 1]; index--; } array[index] = value; } }
Algorithm: sortIt()
1.
A) Minimum Statements. How many statements would be executed in a call to sortIt() when the array size is zero (n == 0) or one (n == 1)?
B) Best Case Scenario. The sortIt() outer loop depends only on n, but the inner loop is sensitive to the ordering of elements in the array and the current index of the outer loop. Under what conditions would the minimum number of inner loop iterations occur when n is large? What is the growth function under these conditions?
C) Worst Case Scenario. The sortIt() outer loop depends only on n, but the inner loop is sensitive to the ordering of elements in the array and the current index of the outer loop. Under what conditions would the maximum number of inner loop iterations occur for an array where n is large? What is the average number of inner loop iterations per outer loop iteration? What is the growth function under these conditions?
Additionally, what arguments could I add to the command line or surrounding the method itself to verify the answers to these questions?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
