Conversation
Implement Hash Set (HashSet.java)END OF FORMAT Remember: The student's solution is in Java, and the reference solution is also in Java. The problem is to implement a HashSet without using built-in hash table libraries. Let's evaluate the student's solution step by step. First, the student's code: class MyHashSet {
int primaryBuckets;
int secondaryBuckets;
boolean[][] storage;
public MyHashSet() {
primaryBuckets = 1000;
secondaryBuckets = 1000;
storage = new boolean[primaryBuckets][];
}
private int getPrimaryHash(int key) {
return key % primaryBuckets;
}
private int getSecondaryHash(int key) {
return key / secondaryBuckets;
}
public void add(int key) {
int primaryIndex = getPrimaryHash(key);
if (storage[primaryIndex] == null) {
if (primaryIndex == 0) {
storage[primaryIndex] = new boolean[secondaryBuckets + 1];
} else {
storage[primaryIndex] = new boolean[secondaryBuckets];
}
}
int secondaryIndex = getSecondaryHash(key);
storage[primaryIndex][secondaryIndex] = true;
}
public void remove(int key) {
int primaryIndex = getPrimaryHash(key);
if (storage[primaryIndex] == null) {
return;
}
int secondaryIndex = getSecondaryHash(key);
storage[primaryIndex][secondaryIndex] = false;
}
public boolean contains(int key) {
int primaryIndex = getPrimaryHash(key);
if (storage[primaryIndex] == null) {
return false;
}
int secondaryIndex = getSecondaryHash(key);
return storage[primaryIndex][secondaryIndex];
}
}Now, let's evaluate based on the criteria:
VERDICT: NEEDS_IMPROVEMENT Implement Min Stack (MinStack.java)Your solution is well-structured and meets the problem requirements. Here are some points to consider:
Overall, great job! Your solution is correct and efficient. VERDICT: PASS |
No description provided.