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.
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. :)
Is the following hashCode() valid? That is, would a hashtable be able to properly store keys...
Implement the remove() and the rehash() methods for the following externally chained hash table. Note you should rehash when "size > arraySize" at the start of the put() method. The new size of the arraySize should be "(2 * old array size) + 1" import java.util.ArrayList; import java.util.Hashtable; import java.util.LinkedList; import java.util.Map; public class ExternalChainingHashTable<K,V> { private class Mapping { private Mapping next; private K key; private V value; private Mapping(K key, V value) { this.key = key; this.value =...
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 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 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) 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 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 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 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...
PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...
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...