【发布时间】:2015-01-07 17:16:27
【问题描述】:
感谢您的帮助
words = [....#Big list of words]
words_set = set(words)
当 n=len(words) 时,我很难确定 set(words) 的复杂度。 它是 O(n),因为它在列表的所有项目上移动,还是 O(l(n-l)),当 l 是单个字长时? 感谢帮助!如果WC和BC之间也有区别。
编辑:不要介意 O(l(n-l)) 重复子字符串大 O 是错误的。
【问题讨论】:
-
我不认为“字长”很重要,或者更确切地说,假设所有字的长度相同,它应该是一个恒定的影响,因此微不足道。
标签: python python-3.x set big-o asymptotic-complexity