Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何决定表达算法的时间复杂度?
O(n)我们应该选择用或来表达时间复杂度theta(n)吗?因为函数f(n)可以表示为Big-Oh(g(n))或theta (g(n))。
O(n)
theta(n)
f(n)
Big-Oh(g(n))
theta (g(n))
我们什么时候选择 big-oh 而不是 theta ?
如果您还想指定下限,请使用 Big Theta 表示法。f(n) = O(g(n))说 that 以f为界g,而f(n) = Theta(g(n))说 thatf以 上下为界g。
f(n) = O(g(n))
f
g
f(n) = Theta(g(n))
换句话说,有常数k1和k2这样的k1 * |g(n)| <= |f(n)| <= k2 * |g(n)|
k1
k2
k1 * |g(n)| <= |f(n)| <= k2 * |g(n)|