Here you can find the source of binarySearch(int arr[], int low, int high, int key)
static int binarySearch(int arr[], int low, int high, int key)
//package com.java2s; //License from project: Apache License public class Main { static int binarySearch(int arr[], int low, int high, int key) { if (low > high) { return -1; }/*from ww w. j a va 2s .c o m*/ int middle = (low + high) / 2; if (arr[middle] == key) { return middle; } else if (key > arr[middle]) { return binarySearch(arr, middle + 1, high, key); } else { return binarySearch(arr, low, middle - 1, key); } } }