Test - /base cases if(i==j&& num[i]==x return i else...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public static void main(String [] args) { public static int binSearch(int[] num, int x) { int n = num.length; if(n == 0 || x > num[n-1] || x < num[0]) return -1; else return binRec(num,x,0,n-1); } public static int binRec(int[] num, int x, int i, int j)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { //base cases if(i==j && num[i]==x) return i; else if(i==j && num[i]!=x) return -1; int k = (int) Math.floor((i+j)/(2.0)); //recursive cases if(x<=num[k]) return binRec(num, x, i, k); else return binRec(num, x, k+1, j); }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online