Week 3: Hashing Flashcards

1
Q

What are the different implementations of a Dictionary ADT in Java? What are the time complexities for their:

get(key)

put(key, data)

remove(key)

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

What are the design issues with a hash table?

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

In a hash table, what type are keys allowed to be?

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

What do hash functions do?

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

A hash function consists of…

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

How do you convert a character to an integer?

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

What is an example of bad hash code?

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

What is polynomial hash code?

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

What does a function with polynomial hash code look like? What is Horner’s rule?

A

\

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

What is the algorithm for computing the hash using a polynomial hash code and Horner’s rule?

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

What is separate chaining with regards to collision resolution?

What is the algorithm for the get(key) method using this approach?

What is the time complexity?

Drawbacks of this approach?

A

Seperate chaining uses an array containing linked lists at each possible index, it then iterates over the linked list at an index for the specific key.

Time complexity is O(n) for bad hash function

Time complexity is O(n/M) = O(1) for good hash function, where M>=n

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

What is Open Addressing with regards to collision resolution?

What is the algorithm for the get(key) method using this approach?

What is the time complexity?

Drawbacks of this approach?

What happens in this technique when an element is deleted?

A

Uses Linear Probing to fill next available empty spaces when collision occurs.

Time complexity is O(n)

When an element is removed/deleted, the array at that index is filled with “deleted” keyword to avoid returning NULL which is what is there when the list is first empty (when there are no elements with that hash key)

Linear Probing: a technique used in open addressing to find the next suitable position in a table

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

What is Double Hashing with regards to collision resolution?

What is the time complexity?

Drawbacks of this approach?

A

Double hashing: use another hash function in order to compute an OFFSET from the original hash.

Both the q value and the M value must be prime numbers

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

What is the algorithm for the Open Addressing put() method?

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

What is the algorithm for the Open Addressing’s put() method using double hashing?

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

What are the average time complexities of Linear probing, double hashing, and seperate chaining?

What are the use-case scenarios for each?

A