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
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...
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?
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....
The function needs to have at least one maximum or minimum value.    A.       Create a...
The function needs to have at least one maximum or minimum value.    A.       Create a function that requires quotient rule (with a variable in the denominator). The function needs to have at least one maximum or minimum value.    Please show work and guidance! "Provide graph" 1. Find any horizontal and vertical asymptotes for this graph as well. 2.        Find the domain of f(x) 3.       Find the y-intercept f(x) 4.        End behavior: Find the limit of the f(x) as...
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?
Provide an Example of a good that you think is a public good at least some...
Provide an Example of a good that you think is a public good at least some of the time. Is it publically or privately provided?
Obviously, it is important to know which suppliers are good and which are bad. There are...
Obviously, it is important to know which suppliers are good and which are bad. There are many ways companies attempt to develop & maintain this knowledge. Some ways are easy to develop and use, others are hard. 1) Give an example of at least 3 different ways you could attempt to measure whether a vendor is good or bad. 2) Under what circumstances would you prefer each approach?
Which of the following items would be the most important to the least important and why?...
Which of the following items would be the most important to the least important and why? Project objectives Goals Sub-phases Tasks Resources Budget Schedule
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT