Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Interpolation Search for Strings ??

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

     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;


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    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.

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Interpolation Search for Strings ??

    NEVER MIND , SOLVED IT MY SELF, THANKS THOUGH FOR THE REPLY

Similar Threads

  1. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 10:09 PM
  2. Having trouble with strings
    By Reaperkid77 in forum Java SE APIs
    Replies: 3
    Last Post: October 20th, 2009, 06:30 PM
  3. Help me this code! Someone please explain strings!
    By helpthiscode in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 16th, 2009, 03:13 AM
  4. Strings
    By BeSwift21 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 13th, 2009, 07:02 PM
  5. Replies: 2
    Last Post: June 19th, 2008, 03:58 AM