import java.util.*; public class SearchComparison { public static void main (String[] argv) { // Fill an array with some random values - for testing. int size = 10; int[] testData = makeRandomSortedArray (size); // Generate a random search term. int value = UniformRandom.uniform (1, size); // Simple search. boolean found = simpleSearch (testData, value); System.out.println ("found = " + found); // Binary. found = binarySearch (testData, value, 0, testData.length-1); System.out.println ("found = " + found); } static boolean simpleSearch (int[] A, int value) { for (int i=0; i end) { return false; } // Find the middle: int mid = (start + end) / 2; if (A[mid] == value) { return true; } else if (value < A[mid]) { // Search the left half: A[start],...,A[mid-1] return binarySearch (A, value, start, mid-1); } else { // Search the right half: A[mid+1],...,A[end] return binarySearch (A, value, mid+1, end); } } static int[] makeRandomSortedArray (int length) { int[] A = new int [length]; for (int i=0; i