Improving performance with advanced data structures
There are more data structures available to us than the ones covered in this chapter thus far. Sometimes, instead of improving our use of a data structure, such as a list, array, tree, stack, or queue, we should implement more advanced data structures that are tailored to our specific use case and then optimize their use.
Let’s look at some additional, more advanced, data structures that have performance considerations.
Hash tables
We can use hash tables when we need fast key-value lookups. There are multiple hash functions to choose from and you should be mindful of hash collisions – they need to be managed efficiently. Some additional considerations are load factor, resizing, memory usage, and performance.
Here’s an example of how to create a hash table:
import java.util.HashMap; HashMap<String, Integer> hashMap = new HashMap<>(); hashMap.put("Alice", 25);
Graphs
Graphs...