function [ Ind] = exponSearch(arr, n, x) if arr(0) == x currentIndex = 0; end i=1; while i<n && arr(i) <= x i= i.*2; Ind = binSearch(V, i/2, min(i,n), x); end function Cind = binarySearch(V, l, r, x) if r >= l mid = ceil(l+(r-l)/2); if V(mid) == x end %if the target is smaller than the middle element
if V(mid) >x Cind= binSearch(V, l, mid-1,x); disp(Cind); end Cind = binSearch(V,mid+1,r,x); end endend
MATLAB: Debugging help for the exponential search code below
expontential search algorithmmatlab function
Best Answer