Week 4 Flashcards

1
Q
HashCode
A = 8
B=3
C=4
D=6
What is min. number of buckets required for no collission
A
6
Use Modulus to assign Buckets
8%6 = 2
3%3=3
4%3=1
6%3=0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When does Collision occur

A

When two elements get mapped to the same index of the underlying array that makes up the HashSet.
Two DiFFERENT element are being hashed identical.
Trying to add a duplicate element to a HashSet does not qualify as collision.

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

Hashing - Open Addressing

A

Placing new element with a duplicate hashcode into the first available (i.e. empty) array index after its own

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

Hashing - Separate Chaining

A

Using an array of LinkedLists, so that at each index of the array, elements with the same hashcode get placed into a LinkedList together.

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

Given a hash set of n buckets that utilizes separate chaining to handle collisions, if there are k elements in a bucket b, and you are searching for an element with hash code b, what is the time complexity of that specific operation? Select the best answer.

A

O(k)
Since we know that the element, if it exists, would be located in the bucket b, in order to determine if it does exist, we have to compare it with each of the k elements in the bucket in the worst case. Accessing the list in the bucket b is an O(1) operation due to being a simple index access.

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