Hash Maps Flashcards

1
Q

What is a Hash Map?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is a Hash Map typically expressed in memory?

A

A Hash Map is typically expressed as a large array in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What types of keys can a Hash Map accept?

A

A Hash Map can accept a variety of key types, including strings, doubles, dates, and even custom classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the key characteristics of a Hash Map?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is recursion involved in the operations of a Hash Map?

A

No, recursion is not involved in the operations of a Hash Map.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the approach to implementing a Hash Map?

A

The approach to implementing a Hash Map involves creating a big array called buckets and writing a hashing function for the non-integer keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the hashing function in a Hash Map?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is the modulo operator used in a Hash Map?

A

The modulo operator (%) is used to determine which bucket in the array to look into based on the hashed key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can collisions occur in a Hash Map?

A

Yes, collisions can occur in a Hash Map, where two different keys hash to the same index in the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does the Java API handle collisions in a Hash Map?

A

The Java API handles collisions in a Hash Map by using a technique called chaining.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the advantage of using chaining to handle collisions in a Hash Map?

A

The advantage of using chaining for collision resolution in a Hash Map is that it can handle an arbitrary number of collisions efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens when there are many collisions in a Hash Map?

A

When there are many collisions in a Hash Map, it can result in degraded performance and increased lookup time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Is it possible for a key to be stored in multiple buckets in a Hash Map?

A

No, in a Hash Map with chaining, each key is stored in a single bucket, even if there are collisions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can you retrieve data from a Hash Map?

A

Data can be retrieved from a Hash Map using the get method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you declare your own Hash Map in Java?

A

In Java, you can declare your own Hash Map using the HashMap class provided by the Java API.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the requirements for keys and values in a Hash Map?

A

In a generic Hash Map, both the key and value must be class types.

16
Q

Do you have to write a hash function for a Hash Map?

A

No, you don’t have to write a hash function for a Hash Map as many hash functions are pre-implemented in the API for common data types such as String, Double, etc.

17
Q

Why would you consider overriding the hashCode method for a class used as a key in a Hash Map?

A

You might consider overriding the hashCode method for a class used as a key in a Hash Map to achieve a better spread of keys and improve the efficiency of the Hash Map.

18
Q

What is the benefit of adding the hash codes of non-static attributes in the hashCode implementation?

A

Adding the hash codes of non-static attributes in the hashCode implementation can help improve the uniqueness and spread of keys in a Hash Map.