Question
*JAVA ONLY* /** * Return index where value is found in array or -1 if not found. * @param array ints where value may be
*JAVA ONLY*
/** * 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started