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.
/** * Return index where value is found in array or -1 if not found. * @param array ints where value may be found * @param value int that may be in array * @return index where value is found or -1 if not found */ public static int find(int[] array, int value) { for (int i = 0; i < array.length; i++) { if (array[i] == value) { return i; } } return -1; }
Algorithm: find()
1.
A) Minimum Statements. How many statements would be executed in a call to find() when the array size is zero (n == 0)?
B) Best Case Scenario. Under what conditions would the minimum possible number of loop iterations be executed for an array where n is large? Where would the target element be located in the array? What is the growth function under these conditions?
C) Worst Case Scenario. Under what conditions would the maximum number of loop iterations be executed for an array where n is large? What would be necessary such that the loop cannot exit early? 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
