hi!im a student and we have an exercise where we are asked to search for a client of our "bookstore" with interpolation search.The codes are saved in a Code[1000] matrix.The type of each code is like that: for example: AY568UTH or MLK1211 etc. Im new at programming and i dont know how to do it with interpolation search.Ive only used interpolation search for Integer. Please help me...post an algorithm or just help :P thanks alot guys!

}
        int InterpolationSearch(int[] Age,String[] Code,int Books[],int[] Total,int[] Deficit,int key,int low,int high){
                final int Not_found=-1;
                while(Age[low]<key & Age[high]>=key){
                int mid=low+((key-Age[low])*(high-low)/(Age[high]-Age[low]));
                if(Age[mid]<key)
                    return InterpolationSearch(Age,Code,Books,Total,Deficit,key,mid+1,high);
                else if(Age[mid]>key)
                    return InterpolationSearch(Age,Code,Books,Total,Deficit,key,low,mid-1);
                else
                    return mid;                     }

                if (Age[low]==key)
                        return low;
                else
                    return Not_found;

Edited 3 Years Ago by mike_2000_17: Fixed formatting

the problem is findng mid when Age[low] or Age[high] are Strings

only one think goes to my head, reduce problem to binary search
where int mid = (high+low)/2
key is String type.
or use transcoder for digits with base 34 (10 decimal digits + 24 letters)

This article has been dead for over six months. Start a new discussion instead.