Binary search with Recursion
Binary search with Recursion: solved Java program for ISC Class 12 Computer Science with complete BlueJ code, explanation and sample output.
Binary search with Recursion
Binary Search
public class RecBinarySearch {
public static int recBinarySearch(int[] sortedArray, int start, int end, int key)
{
if (start <=end) {
int mid = (start+end)/2;
if (key < sortedArray[mid])
{
return recBinarySearch(sortedArray, start, mid-1, key);
} else if (key > sortedArray[mid])
{
return recBinarySearch(sortedArray, mid+1, end , key);
}
else
{
return mid;
}
}
return -1;
}
public static void main() {
int[] arr1 = {2,45,234,567,876,900,976,999};
int end=arr1.length-1;
int index = recBinarySearch(arr1,0,end,999);
if(index!=-1)
System.out.println("Element Found at "+index+" index");
else
System.out.println("Element not Found ");
}
}
Watch java videos
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.