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
2
Q
What is the main advantage of hash sets over lists in Python?
A
It eliminates any duplicates
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
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
5
Q
How can we initialize multiple values into our set?
A
set([1, 2, 3])
result will be = {1, 2, 3}
6
Q
How can we initialize multiple values into a set using list comprehension?
A
mySet = {i for i in range(5)}
7
Q
A