public class LinearHashTable {
void put(DataStruct ds) {
// For the test, we don't have to worry about table expansion.
int hv = getHashValue(ds.getKey());
while(list[hv % tableSize] != null &&
!list[hv % tableSize].getKey().equals(ds.getKey())) {
hv++;
// q++; <-- for quadratic
}
list[hv % tableSize] = ds;;
// list[hv + q * q % tableSize] <-- for quadratic
}
DataStruct get(String key) {
int hv = getHashValue(key);
while(list[hv % tableSize] != null &&
!list[hv % tableSize].getKey().equals(key)) {
hv++;
}
return list[hv % tableSize];
}
}
In order to expand the table, you expand it to twice its size rounded up to the next prime.
- Add
DataStruct
s toPriorityQueue
- Ensure you implement
Comparable
- Build the tree
# Building the tree
while(queue.size > 1)
pop left
pop right
create tree from left and right
add root of tree to queue
- Make compression table
- Go through data
- Look up bit sequence for each symbol
- Print bit sequence
- Get one bit at a time
- Walk tree
- Encounter a leaf
- Output the value
Graph will be undirected
- Listing result of breadth-first search
- Listing result of depth-first search
- Creating an adjacency matrix
- Topological sort
- Dijkstra's algorithm
- Kruskal