这个问题解释了它,但是Python中的集差运算的时间复杂度是多少?
前任:
A = set([...])
B = set([...])
print(A.difference(B)) # What is the time complexity of the difference function?
Run Code Online (Sandbox Code Playgroud)
我的直觉告诉我,O(n)因为我们可以遍历集合 A 并且对于每个元素,查看它是否在恒定时间内(使用哈希函数)包含在集合 B 中。
我对吗?
(这是我遇到的答案:https : //wiki.python.org/moin/TimeComplexity)