【发布时间】:2020-03-31 23:39:50
【问题描述】:
我正在阅读 CPython 中的 time complexity of set operations 并了解到集合的 in 运算符的平均时间复杂度为 O(1),最坏情况下的时间复杂度为 O(n)。我还了解到最坏的情况不会发生在 CPython unless the set's hash table's load factor is too high。
这让我想知道,CPython 实现中何时会出现这种情况?有没有简单的演示代码,显示了in 运算符的O(n) 时间复杂度明显可见的集合?
【问题讨论】:
标签: python set time-complexity cpython in-operator