Hash Sets Flashcards

1
Q

What is the time complexity of searching and inserting values into a hash set in Python?

A

O(1) - constant

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

What is the main advantage of hash sets over lists in Python?

A

It eliminates any duplicates

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

How would we look for the value 1 in the following hash set:

{0, 1, 2, 3}

A

print(1 in mySet)

Will return True

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

How can we remove values in a hash set and what is the time complexity of this operation?

A

mySet.remove(1), O(1) time

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

How can we initialize multiple values into our set?

A

set([1, 2, 3])

result will be = {1, 2, 3}

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

How can we initialize multiple values into a set using list comprehension?

A

mySet = {i for i in range(5)}

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