Sri*_*ram 6 python performance big-o dictionary hashmap
在Python中,我们知道在字典中查找键需要O(1)的运行时间,但在dictionary.values()中查找的运行时间是多少?
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?
Run Code Online (Sandbox Code Playgroud)
编辑#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?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3544 次 |
| 最近记录: |