hash maps Flashcards

(27 cards)

1
Q

What data can be stored in an abstract data type?

A

Stores collection of (key, value) pairs

Each possible key appears at most once and allows access to elements using a key.

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

What is the insert operation in an abstract data type?

A

Adds a new (key, value) pair to the collection, mapping the key to its new value

Any existing mapping is overwritten.

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

What does the remove operation do in an abstract data type?

A

Removes a (key, value) pair from the collection, unmapping a given key from its value.

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

What is the search operation in an abstract data type?

A

Finds the value of the corresponding key and returns its value

If no value exists, returns a default value like zero or null.

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

What is a hash table?

A

Uses a hash function to map a universe of keys to slots on the hash table.

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

What is the time complexity of searching in a hash table with chaining?

A

Θ(1 + α) under the assumption of simple uniform hashing.

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

What is a direct address table?

A

An array where each slot corresponds to a key in the universe of keys.

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

How does the delete operation work in a direct address table?

A

Sets T[x.key] = NULL.

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

What is the load factor of a hash table?

A

α = n / m

Load factor is the average number of elements per slot.

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

What is simple uniform hashing?

A

Each key is equally likely to hash to an integer between 0 and m - 1.

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

What happens when a collision occurs in a hash table?

A

Two keys map to the same location in the hash table.

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

What are the methods to resolve collisions in a hash table?

A
  • Chaining
  • Linear probing
  • Quadratic probing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is chaining in hash tables?

A

All keys that hash to the same slot are placed into the same linked list.

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

What is linear probing?

A

Places the element in the next available slot.

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

What is quadratic probing?

A

Adds a function of i to the hash value.

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

What is the consequence of a high load factor in hash tables with chaining?

A

Increased look-up time due to long linked lists.

17
Q

True or False: Hash functions should be collision resistant.

18
Q

What is a perfect hash function?

A

Injective hash function where every element in S maps to a different value.

19
Q

What is the hashing function for linear probing?

A

H(k,i) = h’(k) + i mod m for i = 0, …, m - 1.

20
Q

What are the pros of chaining in hash tables?

A
  • No need for resizing
  • Simple to implement
21
Q

What are the cons of chaining in hash tables?

A

Increased look-up time in the worst case.

22
Q

What is the expected value of the list length nj in simple uniform hashing?

A

Expected value of nj is α.

23
Q

What is the probing number in probing hash tables?

A

A second input to the hash function.

24
Q

What is primary clustering in linear probing?

A

Many collisions can lead to a large number of consecutive slots being filled.

25
What is secondary clustering in quadratic probing?
Probe sequence repeats itself, making it difficult to find an empty slot.
26
What is the relationship between n and m in probing hash tables?
n is always less than or equal to m.
27
Fill in the blank: Each index of the hash table is essentially a starting point for a _______.
linked list.