import java.util.Random; import java.io.PrintWriter; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; class LargestNumber{ public static void main(String[] args){ int len = Integer.parseInt(args[0]); 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 Search()).findLargest(arr,0,arr.length); Double t2 =(System.nanoTime()-t)/1000000.0; System.out.println("Largest number is " + k+", paa:"+t2+"ms."); } } class Search{ int k = 10; /*FUNC*/ int findLargest(int[] arr, int start, int end){ if((end-start) < k){ return largest_baseCase(arr,start,end); } int half = (end-start) / 2; int mid = start + half; /*REC*/ int leftVal = findLargest(arr,start,mid); /*REC*/ int rightVal = findLargest(arr,mid+1,end); 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; } }