Hash Maps Flashcards
What is a Hash Map?
A Hash Map is a data structure that provides fast look-ups and inserts into specific locations, similar to an array, but it does not use integer keys as indexes.
How is a Hash Map typically expressed in memory?
A Hash Map is typically expressed as a large array in memory.
What types of keys can a Hash Map accept?
A Hash Map can accept a variety of key types, including strings, doubles, dates, and even custom classes.
What are the key characteristics of a Hash Map?
The key characteristics of a Hash Map are fast access and overwrite of elements, non-integer keys, and the ability to store key-value pairs.
Is recursion involved in the operations of a Hash Map?
No, recursion is not involved in the operations of a Hash Map.
What is the approach to implementing a Hash Map?
The approach to implementing a Hash Map involves creating a big array called buckets and writing a hashing function for the non-integer keys.
What is the purpose of the hashing function in a Hash Map?
The hashing function in a Hash Map is used to convert non-integer keys into integers for determining the storage location in the array.
How is the modulo operator used in a Hash Map?
The modulo operator (%) is used to determine which bucket in the array to look into based on the hashed key.
Can collisions occur in a Hash Map?
Yes, collisions can occur in a Hash Map, where two different keys hash to the same index in the array.
How does the Java API handle collisions in a Hash Map?
The Java API handles collisions in a Hash Map by using a technique called chaining.
What is the advantage of using chaining to handle collisions in a Hash Map?
The advantage of using chaining for collision resolution in a Hash Map is that it can handle an arbitrary number of collisions efficiently.
What happens when there are many collisions in a Hash Map?
When there are many collisions in a Hash Map, it can result in degraded performance and increased lookup time.
Is it possible for a key to be stored in multiple buckets in a Hash Map?
No, in a Hash Map with chaining, each key is stored in a single bucket, even if there are collisions.
How can you retrieve data from a Hash Map?
Data can be retrieved from a Hash Map using the get method.
How can you declare your own Hash Map in Java?
In Java, you can declare your own Hash Map using the HashMap class provided by the Java API.