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 5 of 5

Thread: hash table probes

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hash table probes

    working on hash table assignment. searching the table for 100 different keys. trying to keep track of total # of probes (linear) for all successful searches and same for failures. also tracking total # of successful searches. my table has variables numberProbesSuccess, numberProbesFail, and totalSuccess.

    my method "find" is not incrementing these proper

       public void find(int key)    // find item with key
          {
    		int numberProbes = 0;
          int hashVal = hashFunc(key);  // hash the key
     
          while(hashArray[hashVal] != null)  // until empty cell,
             {                               // found the key?
    			numberProbes++;
             if(hashArray[hashVal].getKey() == key)
    				{
    				numberProbesSuccess += numberProbes;  // update # of probes for success
    				totalSuccess++;
    //				System.out.println("Number of probes: " + numberProbes);
                return;   // yes, return item
    				}
    			else
    				{
             	hashVal++;                 // go to next cell
             	hashVal %= arraySize;      // wraparound if necessary
             	}
    			} // end while
    		numberProbes++;
    //		System.out.println("Number of probes: " + numberProbes);
    		numberProbesFail += numberProbes;           // update # of probes for failure
          return;                  // can't find item
          }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: hash table probes

    numberProbesSuccess += numberProbes;

    I assume that numberProbes hold the total probes (successful and unsuccessful). If so why are you incrementing numberProbesSuccess by this number? If you have a successful probe, by what value should numberProbesSuccess be incremented by?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hash table probes

    unsuccesful if while loop finds null. numberProbes can be used for successul searches (if the "if" finds == key) in which case the method returns OR for unsuccessful in case null is found, then numberProbes is assigned to numberProbesFail.

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hash table probes

    also, numberProbes resets with each of the 100 calls to find()

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hash table probes

    OK nevermind - I figured it out. This test is being run using different load factors .1, .2, ... , .9

    All of the empirical data matches up with the theoretical (avg # probes for searches), EXCEPT for the .9 load factor. It blows up big time (way more than the theoretical).

Similar Threads

  1. Hash Functions
    By Blueshark in forum Java Theory & Questions
    Replies: 3
    Last Post: July 2nd, 2012, 03:04 PM
  2. hash map iteration
    By uniqe_mohini in forum Member Introductions
    Replies: 2
    Last Post: September 10th, 2011, 10:14 AM
  3. Help: Bug with removing data from a Hash Map
    By seabeach in forum Collections and Generics
    Replies: 4
    Last Post: August 11th, 2011, 11:54 AM
  4. [SOLVED] MD5 hash and MimeMessage problem
    By ArgyrisV in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 19th, 2011, 04:28 PM
  5. convert arraylist to a hash map
    By nadman123 in forum Collections and Generics
    Replies: 1
    Last Post: July 29th, 2009, 04:24 AM