Hashing and Hash Tables Flashcards

1
Q

What is a hash table?

A

A collection of items which are stored in such a way as to make it easy to find them later.

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

What is the correct name for each position within a hash table?

A

A slot.

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

What is a hash function?

A

The mapping between an item and the slot where that item belongs in the hash table.

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

What does the load factor refer to?

A

The number of slots within a hash table that are occupied.

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

What is the calculation for the load factor?

A

Number of items divided by the hash table size.

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

What does a collision or a clash refer to?

A

When two items need to be in the same slot within a hash table.

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

What is a perfect hash function?

A

A hash function which maps each item into a unique slot.

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

What is the complexity of search of a hash table?

A

O(1).

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

What is the folding method for constructing a hash function?

A

It divides the item into equal-size pieces, which are then added together to give the resulting hash value, which is remainder divided by the size of the hash table.

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

What is the mid-square method for constructing a hash function?

A

It squares the item, then extracts a portion of the resulting digits, which are then divided by the number of slots within the hash table.

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

Why does the hash function have to be efficient?

A

So that it does not become the dominant part of the storage and search process.

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

What does collision resolution refer to?

A

A systematic method for placing the second item of two items which have collided.

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

How does open addressing work?

A

Moving through the hash table sequentially from the collision slot until we encounter the first slot that is empty.

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

What is linear probing?

A

Systematically visiting each slot one at a time.

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

What is a disadvantage of linear probing?

A

Clustering - the tendency for items to become clusters in the hash table.

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

What can be done to mitigate the problem of clustering with linear probing?

A

Extending the technique to skip slots, such as using a ‘plus three’ probe.

17
Q

What does ‘rehashing’ refer to?

A

The process of identifying another slot after a collision has occurred.

18
Q

What is quadratic probing?

A

Instead of using a constant value, we use a rehash function that increments the has value by 1, 3, 5, etc.

19
Q

What is chaining?

A

Each slot contains a collection of items rather than a single item, which can then be searched using a suitable search method.