In: Computer Science
Write a method named minimumValue, which returns the smallest value in an array that is passed (in) as an argument. The method must use Recursion to find the smallest value. Demonstrate the method in a full program, which does not have to be too long regarding the entire code (i.e. program). Write (paste) the Java code in this word file (.docx) that is provided. (You can use additional pages if needed, and make sure your name is on every page in this word doc.) Use the following array to test the method: int[] series array = {-5, -10, +1999, +99, +100, +3, 0, +9, +300, -200, +1, -300} Make sure that the series array only tests for values, which are positive, given your recursive method.
Part II (25 points) Algorithmic Performance as you are aware, consists (mainly) of 2 dimensions: Time and Space. From a technical perspective, discuss the following: Regarding runtime, discuss algorithmic performance with respect to its runtime performance. As you develop an algorithm, what must you also consider in terms of some of the trade-offs? How would you go about estimating the time required for an algorithm’s efficiency (i.e. time to complete in terms of its potential complexity)? What techniques can you use? Give an example of how to measure it.
Code
public class Minimum {
public static int minimumValue(int arr[], int n) {
// if there is only one element then that is the least one
if (n == 1) {
if (arr[0] > 0)
return arr[0];
//return a comparatively large value
return 999999999;
}
// else recursively call the method
if (arr[n - 1] < 0)
return Math.min(999999999, minimumValue(arr, n - 1));
return Math.min(arr[n - 1], minimumValue(arr, n - 1));
}
public static void main(String args[]) {
int[] series_array = { -5, -10, +1999, +99, +100, +3, 0, +9, +300, -200, +1, -300 };
// call the above method
int min = minimumValue(series_array, series_array.length);
// print the value
System.out.println("The minimum positive value is : " + min);
}
}
Screenshot
Output