Hide text Hide pseudo-code | |
Find the given key from the table by using binary search. Some addditional problems. int binarySearch(int table[],int x) { int low = 0; int high = table.length - 1; int mid; while( low <= high ) { mid = (low + high) / 2; if( table[mid] < x) low = mid + 1; else if(table[mid] > x) high = mid - 1; else return mid; } return -1; // Not found } |