hash table method to find element and count number of probes

I have a hashtable class where everything is working, except in my find method, I want to count the number of probes. It seems that if my desired element was not found, I should get number of probes equal to the table size.
heres the code:
public class myHash2
{
  //data members
  private hashNode[] space;
  private int count;  //number of elements in table
  private int probes = 0; //number of ties to insert element
  private int findprobes = 0;  //number of tries to find element
   
  //letters for the int keys to be converted to
  String s = "abcdefghijklmnopqrstuvwxyz";
     public myHash2(int n)     {        
      while(!isPrime(n))
      {
        n++;
      }
      space = new hashNode[n];
      count = 0;
    }
   
    public static boolean isPrime(int n)
    {
      if(primeHelper(n) == 1)
        return true;
      else
        return false;
    }
   
    public static int primeHelper(int n)
    {
      if(n < 0)
        throw new IllegalArgumentException
        ("positive integer must be entered, " + n + "entered.");
      int sum = 1;
      for(int i = (n - 1); i >= 2; i--)
      {
        if((n % i) == 0)
        {
          sum += n;
        }
      }
      return sum;
    }
       
    public int getProbes()
    {
      return probes;
    }
   
    public int getFindprobes()
    {
      return findprobes;
    }
   
    public int getCount()
    {
      return count;
    }
    public double find(int k)
    {
      int i = 0;
      int findprobes = 0;
      while(findprobes < space.length &&
            space[rehash(k,i)] != null &&
            space[rehash(k,i)].getKey() != k)
      {
          i++;
          findprobes++;
      }
      if((i < space.length) && (space[rehash(k,i)] != null))
      {
        System.out.println("probed " + findprobes + " times, item " + s.charAt(k) + " found");
        return (space[rehash(k,i)].getData());
      }
      else  
        System.out.println("probed " + findprobes + " times, item " + s.charAt(k) + " not found");
      return 0;
    }
     public boolean fullTable()
    {
      return (space.length == count);
    }
    public void insert(int key, double data)
    {
      probes = 0;
      if(fullTable())
      {
        System.out.println("table is full, cannot insert");
        System.exit(0);
      }
      hashNode h = new hashNode(key, data);
      int index = hash(key);
      int attempt = 0;
      for(int i = 0; i < space.length; i++)
      {
        if(space[index] == null)
        {
          space[index] = h;  
          attempt++;
          probes++;
          System.out.println("probed " + probes + " times to insert " + s.charAt(key));
          break;
        }
        else
        {
          if(space[index].getKey() == key)
          {
            space[index].setData(data);
            break;
          }
          index = rehash(key, attempt);  
          attempt++;
          probes++;
          System.out.println("probed " + probes + " times to insert " + s.charAt(key));
        }
      }
      count++;
    }
          int hash(int key)
    {
      return (key % space.length);
    }
     int rehash(int key, int attempt)
    {
      findprobes++;
      return ((hash(key) + (attempt * attempt)) % space.length);
    }
}

heres the test program:
import java.util.*;
public class hashTest2
{
  public static void main(String[] args)
  {
    Random r =new Random();
    myHash2 m = new myHash2(15);
   
    for(int i = 0; i < 15; i++)
    {
      int x = r.nextInt(25);
      double  y = r.nextDouble() * 10;
      m.insert(x, y);  
    }
    System.out.println();  
    for(int i = 0; i < 15; i++)
    {
      int z = r.nextInt(25);
      m.find(z);
    }
  }
}
my find operation works, but doesn't give me reasonable findprobes count.
where did I go wrong, I have tried a lot of things
thanks
DAJonesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
i think the cause is that u r increminting findprobes inside rehash() method, and inside the find() method u r using rehash() 4 times and u increment findprobes a 5th time inside find()
hence I think u replicated the increament multiplied by fife times more than it suppose

count urself  how many times u use rehash inside find
0
DAJonesAuthor Commented:
I took out the findprobes++ in the find method. here is my output from the 2nd loop in test:
probed 0 times, item b found
probed 0 times, item e not found
probed 0 times, item c found
probed 0 times, item x not found
probed 0 times, item h found
probed 0 times, item i not found
probed 0 times, item t not found
probed 0 times, item o found
probed 0 times, item n not found
probed 0 times, item j not found
probed 0 times, item q found
probed 0 times, item j not found
probed 0 times, item m found
probed 0 times, item q found
probed 0 times, item i not found

0
petmagdyCommented:
here we go the same old mistake in ur find function:

    public double find(int k)
    {
      int i = 0;
      int findprobes = 0;   <---- // rename this value to another and replace in the whole function

or just:
>>int findprobes = 0;
replace with:
findprobes = 0;

ur choice
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

DAJonesAuthor Commented:
I made these changes:
public double find(int k)
    {
      int i = 0;
      findprobes = 0;
      while(i < space.length &&
            space[rehash(k,i)] != null &&
            space[rehash(k,i)].getKey() != k)
      {
          i++;
      }
      if((i < space.length) && (space[rehash(k,i)] != null))
      {
        System.out.println("probed " + findprobes + " times, item " + s.charAt(k) + " found");
        return (space[rehash(k,i)].getData());
      }
      else  
        System.out.println("probed " + findprobes + " times, item " + s.charAt(k) + " not found");
      return 0;
    }
out put:
probed 2 times, item d not found
probed 3 times, item p found
probed 2 times, item k not found
probed 2 times, item e not found
probed 3 times, item m found
probed 2 times, item v not found
probed 3 times, item m found
probed 2 times, item u not found
probed 2 times, item k not found
probed 3 times, item r found
probed 2 times, item j not found
probed 3 times, item g found
probed 6 times, item f not found
probed 3 times, item s found
probed 3 times, item p found
seems like I should get probed <tablesize> times if the itemisn't found

0
petmagdyCommented:
no ur modification is wrong:
try remove findprobes++ from rehash and add it to the while loop inside find()
0
tdisessaCommented:
You need to change your while logic

if "space[rehash(k,i)] != null" evaluates to false, the program will stop looking.

try this:

      while(i < space.length &&
            (space[rehash(k,i)] == null ||
             space[rehash(k,i)].getKey() != k))

You want to continue looking if
1.  There is nothing in space[<index>], or
2.  There is something and it is not k
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tdisessaCommented:
And "space[rehash(k,i)] != null" would return false if there is anything in "space[rehash(k,i)]"
0
tdisessaCommented:
Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.