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) Expected Average Case Scenario. Assuming a random array of unique elements, what is the expected average number of inner loop iterations per outer loop iteration? How does it compare to the worst case? What is the growth function under these conditions?

B) What is the runtime order (big-O) of sortIt() based on the above growth functions?

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!