In class HashTable implement a hash table and consider the following:
(i) Keys are integers (therefore also negative!) and should be stored in the table
int[] data.
(ii) As a hash function take h(x) = (x · 701) mod 2000. The size of the table is
therefore 2000. Be careful when computing the index of a negative key. For
example, the index of the key x = −10 is
h(−10) = (−7010) mod 2000 = (2000(−4) + 990) mod 2000 = 990.
Hence, indices should be non-negative integers between 0 and 1999!
(iii) Implement insert, which takes an integer and inserts it into a table. The
method returns true, if the insertion is successful. If an element is already in
the table, the function insert should return false.
(iv) Implement search, which takes an integer and finds it in the table. The method
returns true, if the search is successful and false otherwise.
(v) Implement delete, which takes an integer and deletes it form the table. The
method returns true, if the deletion is successful and false otherwise.
(vi) Collision should be solved by chaining. However, not as usually by linked list,
but with a hash table implemented in class HashTable2 (combined structure).
- In class HashTable2 implement a hash table and consider the following:
(i) Keys are integers (therefore also negative!) and should be stored in the table
int[] data.
(ii) As a hash function take h(x) = (x·53) mod 100. The size of the table is therefore
100. As above be careful to compute the index of a negative key correctly. In
this case indices should be non-negative integers between 0 and 99!
1
(iii) Implement insert, which takes an integer and inserts it into a table. The
method returns true, if the insertion is successful. If an element is already in
the table, the function insert should return false. When inserting an element
into a full table, the function insert should return false.
(iv) Implement search, which takes an integer and finds it in the table. The method
returns true, if the search is successful and false otherwise.
(v) Implement delete, which takes an integer and deletes it form the table. The
method returns true, if the deletion is successful and false otherwise.
(vi) Collision should be solved by open-addressing with linear probing. Be careful
when deleting an element. You need a special character to indicate that the
element was deleted so that the function search will work correctly. Also,
be careful when inserting new element, since it can be inserted into the place
indicated with the special character.
The base code for the HashTable class: public class HashTable { HashTable2[] data; public boolean insert(int key) { throw new UnsupportedOperationException("Need to implement this function"); } public boolean search(int key) { throw new UnsupportedOperationException("Need to implement this function"); } public boolean delete(int key) { throw new UnsupportedOperationException("Need to implement this function"); } }
The base for the HashTable2 class:
public class HashTable2 {
int[] data;
public boolean insert(int key) {
throw new UnsupportedOperationException("Need to implement this function");
}
public boolean search(int key) {
throw new UnsupportedOperationException("Need to implement this function");
}
public boolean delete(int key) {
throw new UnsupportedOperationException("Need to implement this function");
}
}
to generate a solution
a solution
- We may utilise two methods without implementing them: countand unambiguous The DictionaryEntry object's count is returned via the Count method. whereas Clear removes all DictionaryEntry from the inner hash tableitems from the internal hash tableWrite a program that utilizes these methods:arrow_forwardThe putIfAbsent function in HashMap seems useless.arrow_forwardThis is the code below: package hashset; import java.util.Iterator; public class MySet { // implements a set using a separate chaining hash table privateclass Node { private Integer element; private Node next; private Node(Integer e, Node n) { element = e; next = n; } } private Node table[]; //an array of linked list privateinttableSize; //current number of lists in the table privateintnumElements; //number of elements in the set privatefinalintprimes[] = {7, 23, 59, 131, 271, 563, 1171, 2083, 4441, 8839, 16319, 32467, 65701, 131413, 263983, 528991}; privateintprimeIndex; //last prime used privateint nextPrime(intp) { //finds the next prime from the list above //used for resizing and the initial size while (primes[primeIndex] <= p) primeIndex++; returnprimes[primeIndex]; } public MySet(ints) { //s is a hint for the initial size primeIndex = 0; tableSize = nextPrime(s); table = new Node[tableSize]; numElements = 0; } //return the hash function value for k privateint…arrow_forward
- import hashlib def hash_function(password, salt, al): if al == 'md5': #md5 hash = hashlib.md5(salt.encode() + password.encode()) hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif (al == 'sha1'): #sha1 hash = hashlib.sha1() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif al == 'sha224': #sha224 hash = hashlib.sha224() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif al == 'sha256': #sha256 hash = hashlib.sha256() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt elif al == 'blake2b': #blake2b512 hash = hashlib.blake2b() hash.update(password.encode('utf-8')) return hash.hexdigest() + ':' + salt else: print("Error: No Algorithm!") if __name__ == "__main__": # TODO: create a list called hash_list that contains # the five hashing algorithsm as strings # md5, sha1, sha224, sha256, blake2b hash_list =…arrow_forwardJava Code: For Lexer.java Make a HashMap of <String, TokenType> in your Lex class. Below is a list of the keywords that you need. Make token types and populate the hash map in your constructor (I would make a helper method that the constructor calls). while, if, do, for, break, continue, else, return, BEGIN, END, print, printf, next, in, delete, getline, exit, nextfile, function Modify “ProcessWord” so that it checks the hash map for known words and makes a token specific to the word with no value if the word is in the hash map, but WORD otherwise. For example, Input: for while hello do Output: FOR WHILE WORD(hello) DO Make a token type for string literals. In Lex, when you encounter a “, call a new method (I called it HandleStringLiteral() ) that reads up through the matching “ and creates a string literal token ( STRINGLITERAL(hello world) ). Be careful of two things: make sure that an empty string literal ( “” ) works and make sure to deal with escaped “ (String quote = “She…arrow_forwardwrite code for :arrow_forward
- import java.util.HashSet; import java.util.Set; // Define a class named LinearSearchSet public class LinearSearchSet { // Define a method named linearSearch that takes in a Set and an integer target // as parameters public static boolean linearSearch(Set<Integer> set, int target) { // Iterate over all elements in the Set for () { // Check if the current value is equal to the target if () { // If so, return true } } // If the target was not found, return false } // Define the main method public static void main(String[] args) { // Create a HashSet of integers and populate integer values Set<Integer> numbers = new HashSet<>(); // Define the target to search for numbers.add(3); numbers.add(6); numbers.add(2); numbers.add(9); numbers.add(11); // Call the linearSearch method with the set…arrow_forwardExcute the Program about Hash and show me the result . Source code import java.util.*; import java.io.*; class HashTable { public static void main(String[] args) throws IOException { int key; try { BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); System.out.print ("How many elements you want to enter to the hash table : "); int n = Integer.parseInt(in.readLine()); Hashtable hashTable = new Hashtable(); for(int i = 0; i < n; i++) { System.out.print("Enter key for the hash table : "); key = Integer.parseInt(in.readLine()); System.out.print("Enter value for the key : "); hashTable.put(key, in.readLine()); } Map map = new TreeMap(hashTable); System.out.println(map); } catch(NumberFormatException ne) { System.out.println(ne.getMessage() + " is not a legal value."); System.out.println("Please enter a numeric value."); System.exit(1); } } }//Endarrow_forwardSuppose you have an object made up of two w-bit integers, x and y. Show why x+y does not make a good hash code for your object. Give an example of a large set of objects that would all have the same hash code. c++ and provide good comments.arrow_forward
- Java - A good guideline for hash tables is that the size should be based on a product of two primes. True or False?arrow_forwardHelp with this java question: Map<KeyType, ValueType> mapName = new HashMap<>();arrow_forwardJava's HashMap is implemented as a hash table. The put method stores a value with its associated key. Assuming that the put method takes .001 seconds for a HashMap containing 1,000 values, roughly how long would you expect put to take when called on a HashMap containing 100,000 values? Group of answer choices .001s .01s .1s 1.0s 10.0sarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education