Unformatted text preview: //found it if (x < arr[mid]) return binsearch(arr,x,left,mid1); else return binsearch(arr,x,mid+1,right); } return 1; // Failed to find ’x’ } Note how the recursive version checks to see if we are at ’x’, then it returns, otherwise it calls itself to solve a smaller problem (see also Epp, Sec. 11.5). Observe that, if a n denotes the worstcase run time, then a n = a ⌊ n 2 ⌋ + 1 , and a n ∈ O ( log n ) . Q3. Sec. 10.1, Ex. 19, 20, 33, 43 Q4. Sec. 10.2, Ex. 8, 12, 15, 18 Page 1 Last updated May 18, 2011 by M. Bajger...
View
Full Document
 Spring '08
 WOUTERS
 Algebra, Big O notation, Computational complexity theory, int arr, Flinders University, int binSearch

Click to edit the document details