import java.util.Random; import java.io.PrintWriter; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; class LargestNumber2{ public static void main(String[] args){ int len = Integer.parseInt(args[0]); int cutOff = Integer.parseInt(args[1]); int cores = Runtime.getRuntime().availableProcessors(); int[] arr = new int[len]; Random r = new Random(123); for(int i = 0; i < arr.length; i++){ arr[i] = r.nextInt(len-1); } long t = System.nanoTime(); /*CALL*/ int k = (new Search2()).findLargest(arr,0,arr.length,cutOff); Double t2 =(System.nanoTime()-t)/1000000.0; System.out.println("Largest number is " + k+", paa:"+t2+"ms."); } } class Search2{ /*FUNC*/ int findLargest(int[] arr, int start, int end, int cutOff){ if((end-start) < cutOff){ return largest_baseCase(arr,start,end); } int half = (end-start) / 2; int mid = start + half; /*REC*/ int leftVal = findLargest(arr,start,mid,cutOff); /*REC*/ int rightVal = findLargest(arr,mid+1,end,cutOff); if(leftVal > rightVal) return leftVal; return rightVal; } int largest_baseCase(int[] arr, int start, int end){ int largest = 0; for(int i = start; i < end; i++){ if(arr[i] > largest){ largest = arr[i]; } } return largest; } } // end class Search2