dictionary.values() 列表与集合中查找的时间复杂度
Time complexity for lookup in dictionary.values() lists vs sets
在Python中,我们知道在字典中查找一个key需要O(1)运行时间,但是在运行中查找的时间是多少? =19=]() ?
dictionary = {'a':[66,77,88], 'b':[99,100]}
key = 'a'
if key in dictionary: # takes O(1) run time
number = '99'
if number in dictionary.values(): # What is the run time here?
编辑 #1:键的值可以是列表或集合。许多人回应说,如果值是列表,则 运行 时间是 O(1)。
如果值是集合,会是O(N)吗?
dictionary = {'a':(66,77,88), 'b':(99,100)}
number = '99'
if number in dictionary.values(): # What is the run time here?
设是x in s
在一个列表中搜索的操作,{x=item,s=list}
平均情况 - 假设参数随机均匀生成 - 对于这种操作将是 O(n)
有关时间复杂度的更多信息,这里是 official link
在Python中,我们知道在字典中查找一个key需要O(1)运行时间,但是在运行中查找的时间是多少? =19=]() ?
dictionary = {'a':[66,77,88], 'b':[99,100]}
key = 'a'
if key in dictionary: # takes O(1) run time
number = '99'
if number in dictionary.values(): # What is the run time here?
编辑 #1:键的值可以是列表或集合。许多人回应说,如果值是列表,则 运行 时间是 O(1)。
如果值是集合,会是O(N)吗?
dictionary = {'a':(66,77,88), 'b':(99,100)}
number = '99'
if number in dictionary.values(): # What is the run time here?
设是x in s
在一个列表中搜索的操作,{x=item,s=list}
平均情况 - 假设参数随机均匀生成 - 对于这种操作将是 O(n)
有关时间复杂度的更多信息,这里是 official link