Question

Is the following hashCode() valid? That is, would a hashtable be able to properly store keys...

Is the following hashCode() valid? That is, would a hashtable be able to properly store keys with this hashCode? Explain.

public int hashCode() {

    return 17;

}

Does a separate chaining hashtable require a resize method to be implemented? What about a linear probing hashtable? Explain.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

The given hash code

public int hashCode() {

    return 17;

}

is somewhat not valid, because based on the number of keys available with the help of hash function resizing needs to be done, if we are storing any key as it is then it will create a lot of memory wastage.

As I explained a resizing method needs to be implemented as well as the collision resolution function, in case of collision what collision resolution technique is going to be used, that is linear probing, quadratic probing or perfect hashing.

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Add a comment
Know the answer?
Add Answer to:
Is the following hashCode() valid? That is, would a hashtable be able to properly store keys...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ANSWER THE FOLLOWING QUESTIONS: Problem 2 Assume that you want to design a hashtable to store data of employees in a co...

    ANSWER THE FOLLOWING QUESTIONS: Problem 2 Assume that you want to design a hashtable to store data of employees in a company. The ID of each worker is his primary phone mumber in the form of 10 digit number (Area code-three digits carrier-4 digits id). Knowing the following constraints (information). a) Employees can differ only on the three low significant digits, the fifth and the sixth digits; they all have the same digits for the fourth, seventh, eighth, ninth and...

  • IN JAVA LANGUAGE: For this lab you are required for implement the following methods: 1. public...

    IN JAVA LANGUAGE: For this lab you are required for implement the following methods: 1. public QuadraticProbingHashTable( int size ): As the signature of this method suggests, this is a constructor for this class. This constructor will initialize status of an object from this class based on the input parameter (i.e., size). So, this function will create the array HashTable with the specified size and initialize all of its elements to be null. 2. public int hash(int value, int tableSize...

  • In this problem, you will complete several classes involving boxes, locks, keys and secrets. Follow the...

    In this problem, you will complete several classes involving boxes, locks, keys and secrets. Follow the specifications in the starter files for the classes. You can run the javadoc program to generate the API (see Tutorial 2) for the classes. A box has a secret inside it (and maybe a key!) and can be locked. In order to open a box, you need the right key to unlock the lock. Secrets.java will be a program that takes an array of...

  • java Create the following classes: DatabaseType: an interface that contains one method 1. Comparator getComparatorByTrait(String trait)...

    java Create the following classes: DatabaseType: an interface that contains one method 1. Comparator getComparatorByTrait(String trait) where Comparator is an interface in java.util. Database: a class that limits the types it can store to DatabaseTypes. The database will store the data in nodes, just like a linked list. The database will also let the user create an index for the database. An index is a sorted array (or in our case, a sorted ArrayList) of the data so that searches...

  • __________________________________________________________________________________________ HashMaps A hashtable is a data structure that allows the user to look up things...

    __________________________________________________________________________________________ HashMaps A hashtable is a data structure that allows the user to look up things by a key value. Java implements a hashtable called “HashMap”. The way it works is to specify two types of classes. One is the “key”, and another is the “value”. You can put data values into the HashMap at an “index” specified by the key. Like ArrayList, HashMap is a generic class, so you declare it using angle brackets. For HashMap, you must include...

  • Hash Tables. (Hint: Diagrams might be helpful for parts a) and b). ) When inserting into...

    Hash Tables. (Hint: Diagrams might be helpful for parts a) and b). ) When inserting into hash table we insert at an index calculated by the key modulo the array size, what would happen if we instead did key mod (array_size*2), or key mod (array_size/2)? (Describe both cases). Theory answer Here Change your hashtable from the labs/assignments to be an array of linkedlists – so now insertion is done into a linkedlist at that index. Implement insertion and search. This...

  • Hello, There are some elements in my code that aren't working properly that need to be...

    Hello, There are some elements in my code that aren't working properly that need to be fixed but I don't know what I have done wrong. The printHealthBars() should print out a '+' for each point of current health and a '-' for each difference between current & max health. So, for instance, suppose the pokemon had 6/8 health, the method should print: "[ ++++++-- ]" Something is up with the damage calculation method. The idea is that it should...

  • Would someone be able to help me with this please? It has to do with Linked...

    Would someone be able to help me with this please? It has to do with Linked List Arrays, and I'm very confused on what to do. Any help along with steps would be very much appreciated. Cheers! You are hired by a company to implement a singly-linked list that will hold integers, using Java programming language. However, the boss of the company insists that you don’t use any objects or structures in your implementation. You may use only integer arrays...

  • Question 1 1 pts Which of the following is not a valid class name in Java?...

    Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...

  • ​​​​​ You should now be able to edit the IntTree class. Implement each of the functions labeled...

    ​​​​​ You should now be able to edit the IntTree class. Implement each of the functions labeled with You are not allowed to use any kind of loop in your solutions. You may not modify the Node class in any way You may not modify the function headers of any of the functions already present in the file. You may not add any fields to the IntTree class. You may not change or remove the line that reads “package hw2;”...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT