Question

In: Computer Science

You want to create a good hash function. Which of these properties is the least important...

You want to create a good hash function. Which of these properties is the least important for your hash function to have?

Let's say you want to store a collection of unique elements. You would like to be able to search, insert, delete as fast as possible. Which data structure should you use?

Let's say you want your hash table to allow load factors greater than 1. You would use:

Solutions

Expert Solution

Code:

package assignment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
class MyDS
{
ArrayList<Integer> arr; // ArrayList is resizable array
HashMap<Integer, Integer> hash; // A hash where keys are array elements and vlaues are
public MyDS() { // Constructor for create array and hash
arr = new ArrayList<Integer>();
hash = new HashMap<Integer, Integer>(); }
void insert(int x) {
if (hash.get(x) != null) // If the element is already present then noting to do
return;
int s = arr.size();// Else put element at the end of array
arr.add(x);
hash.put(x, s); }
void delete(int x) {
Integer index = hash.get(x);
if (index == null)
return;
hash.remove(x); //otherwise remove here
int size = arr.size();
Integer last = arr.get(size-1);
Collections.swap(arr, index, size-1);
arr.remove(size-1);
hash.put(last, index);}// Update hash table for new index of last element
Integer search(int x) {
return hash.get(x);
}}
public class DS {
   public static void main(String args[]) {
   MyDS ds = new MyDS();
ds.insert(10);
ds.insert(20);
ds.insert(30);
ds.insert(40);
System.out.println("Search element of index: "+ds.search(30));
ds.delete(20);
ds.insert(50);
System.out.println("After delete the element: "+ds.search(50));
}}

Note:***I hope you happy with my answer****If you like my answer please give me upvote*****Thank you....


Related Solutions

C# Programming create a Hash Function
C# Programming create a Hash Function
Analyse the security of Lamport’s OLP algorithm with the properties of hash function.
Analyse the security of Lamport’s OLP algorithm with the properties of hash function.
Create a visualization of a hash table containing at least 10 items using one of the...
Create a visualization of a hash table containing at least 10 items using one of the hash table collision techniques covered in this section. Fully describe the image and how the items came to be in their given positions.
what is a good hash function for ID numbers of format "LM-0001312", "LM-04341313", "LM-4205114"
what is a good hash function for ID numbers of format "LM-0001312", "LM-04341313", "LM-4205114"
Deacribe the properties of a good stimator in your own words. Why are these factors important...
Deacribe the properties of a good stimator in your own words. Why are these factors important for an estimator?
1.Describe a design pattern that incents good security behavior. 2.Design a hash function that uses any...
1.Describe a design pattern that incents good security behavior. 2.Design a hash function that uses any desired date as the salt. Demonstrate operation of the function, including input values. Describe benefits and shortcomings of the hash function.
In python i want to create a function. The function will take in two linked lists...
In python i want to create a function. The function will take in two linked lists as the parameters. If one is shorter than the other then the shorter will be the length. I want to take the values from both linked lists and turn them into tuples. I then want these tuples to be put into a new linked list. I want to return that linked list. I want to do this using recursion and no helper functions or...
7. You have a hash function that takes the binary bits of a number, divides it...
7. You have a hash function that takes the binary bits of a number, divides it up into blocks of 4 bits and then XORs the blocks together. So for example, if we have 4 blocks, block X0, X1, X2 and X3, the result of the 4-bit block hash would be X0 XOR X1 XOR X2 XOR X3. For example, the hash of "011011001010" would be "0110" XOR "1100" XOR "1010". Demonstrate that this is a poor hash function by...
Q7. Given application prioritize which properties are most important and explain why. You are evaluating a...
Q7. Given application prioritize which properties are most important and explain why. You are evaluating a new material for a hernia support mesh. This device holds internal organs in position until healing is completed after surgery. Which 3 material properties would you evaluate first and why? Set approximate minimum values for each as well when possible. Q8. Compare and contrast the atomic, lattice, micro and bulk structures of similar materials and explain how they influence the properties of the material....
Which properties of limits are applicable to find the limit of a rational function at a...
Which properties of limits are applicable to find the limit of a rational function at a particular point?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT