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!

Recommended Answers

All 4 Replies

There is no significant difference what we seek.
Post your "Integer" code

}
        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;

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.