Test - { //base cases if(i==j &&...

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 &amp;&amp; num[i]==x) return i; else if(i==j &amp;&amp; num[i]!=x) return -1; int k = (int) Math.floor((i+j)/(2.0)); //recursive cases if(x&lt;=num[k]) return binRec(num, x, i, k); else return binRec(num, x, k+1, j); }...
View Full Document

This note was uploaded on 11/22/2010 for the course BSE 71920 taught by Professor Nakurmura during the Spring '10 term at ASU.

Ask a homework question - tutors are online