Binary Search
int binarySearch(int a[], int n, int key) { int low = 0, high = n - 1, mid = 0; while(low <= high) { mid = (low + high) / 2; if(a[mid] == key) return mid; else if(a[mid] < key) low = mid + 1; else high = mid - 1; } return -1; }
O(logn)