# Interpolation Search for Strings ??

Printable View

• May 16th, 2010, 11:31 AM
george
Interpolation Search for Strings ??
ok, this is for Int types. My problem is that i have to use InterpolationSearch for Strings. For numbers sure it works fine.

Can someone help me with this algorithm please?

Code :

``` public static int InterpolationSearch(int[] a, int x,int low,int high) { // x = key of search int mid; while(low<=high) { mid=low+(high-low)*((x-a[low])/(a[high]-a[low])); if(x==a[mid]) return mid+1; if(x<a[mid]) high=mid-1; else low=mid+1; } return -1;```
• May 16th, 2010, 07:36 PM
helloworld922
Re: Interpolation Search for Strings ??
You'll have to define what you mean by addition/subtraction between different strings since there's no default definition for what these mean.
• May 17th, 2010, 06:52 AM
george
Re: Interpolation Search for Strings ??
ok lets say i have an array with 10000 codes in it : ex ACF02592
DAK30103
PMD15123
GFP65159
DTO31914
FIE58434
HTK71910
RKB17101
OGE14649
MLK12111
DOB31414
FSA51807
............
, which is afterwards sorted with a quick sort.

my problem is exactly in
Quote:

addition/subtraction between different strings
. Can Strings like that have operators like +,-,*,/ used on them ??

ive have come up with this "theory"in my mind : taking the string, then seperate it into two halves , the numbers and the letters. Then convert each letter into it apropriate Number,(i think on keyboard each letter reffers to a set of numbers) then merge it together and convert the whole thing from String to Int. Then send this new array into interpolationsearch, where now you will have only integers and it will worl fine.

The problem is this is all just a theory, and not sure how or what methods to use to do it, and if it will even work.

I know it has to be a quicker way.
• May 18th, 2010, 06:11 AM
george
Re: Interpolation Search for Strings ??
NEVER MIND , SOLVED IT MY SELF, THANKS THOUGH FOR THE REPLY