What is the computational complexity of the following operation:
list1 = [1,2,2,2,3,4,4]
set1 = set(list)
What is the computational complexity of the following operation:
list1 = [1,2,2,2,3,4,4]
set1 = set(list)
It is O(n)
, where n
is the number of elements in the list. set()
is essentially iterating over the list and adding each of those elements to a hash table.