@@ -0,0 +1,1269 @@
+package search;%0A%0A/*%0A%09This class implements Binary Search on array of integers.%0A*/%0A%0Aclass BinarySearch%7B%0A%0A%09// Finds specified key in specified array. %0A%09// Returns index of key in A if search is successful, otherwise returns -1%0A%09// Time complexity: O( log(N) ) %09%09N - Size of array%0A%09// Input array must be sorted in ascending order.%0A%0A%09public static int find(int%5B%5D A, int key)%7B%0A%0A%09%09if(A == null)%0A%09%09%09throw new NullPointerException(%22Array is empty%22);%0A%0A%09%09int beg = 0; %09%09%09%09// Beginning of search space%0A%09%09int end = A.length - 1;%09%09// End of search space%0A%09%09int mid = (beg + end)/2;%09// Middle element in search space%0A%09%09boolean successful = false;%09// Indicates whether search was successful or not.%0A%0A%09%09// while beg is less or equal to end (Search space is valid)%0A%09%09while(beg %3C= end)%7B%0A%0A%09%09%09// If key is equal to middle element, break the loop and set successful flag%0A%09%09%09if(key == A%5Bmid%5D)%7B%0A%09%09%09%09successful = true;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%09// If key lies in lower half, update end%0A%09%09%09else if(key %3C A%5Bmid%5D)%7B%0A%09%09%09%09end = mid - 1;%0A%09%09%09%7D%0A%09%09%09// Otherwise, update beg%0A%09%09%09else%7B%0A%09%09%09%09beg = mid + 1 ;%0A%09%09%09%7D%09%0A%0A%09%09%09// Update mid%0A%09%09%09mid = (beg + end)/2;%0A%0A%09%09%7D%0A%0A%09%09// If found, return index at which key was found%0A%09%09if(successful)%0A%09%09%09return mid;%0A%09%09// else return -1 to indicate faliure%0A%09%09else%0A%09%09%09return -1;%09%09%0A%0A%09%7D%0A%0A%7D%09

Add binary search algorithm