Open justdoit254 opened 2 years ago
The algorithm for Binary search is quiet easy .Here it is: public int runBinarySearchIteratively( int[] sortedArray, int key, int low, int high) { int index = Integer.MAX_VALUE;
while (low <= high) {
int mid = low + ((high - low) / 2);
if (sortedArray[mid] < key) {
low = mid + 1;
} else if (sortedArray[mid] > key) {
high = mid - 1;
} else if (sortedArray[mid] == key) {
index = mid;
break;
}
}
return index;
}
Now if we implement the above algorithm into a code, that will be: BinarySearch_Java.docx
Hi @abhpd , Kindly please assign me this issue.
Algorithm and code of Binary search