考虑一棵插入成本为 的树O(log n)
。假设您从一棵空树开始并迭代添加 N 个元素。我们想知道总时间复杂度。我这样做了:
nb of operations in iteration i = log i
nb of operations in all iterations from 1 to N = log 1 + log 2 + ... + log N = log( N! )
total complexity = O(N!) ~ O(N log N)
(参见斯特林近似http://en.wikipedia.org/wiki/Stirling%27s_approximation)
这个对吗?