Confused on whether to express time complexity with theta notation or Big Oh notation

故事扮演 提交于 2020-01-02 19:10:21

问题


How to decide on expressing time complexity of algorithm ?

Should we choose to express time complexity in terms of O(n) or theta(n) ? Because a function f(n) can be expressed as either Big-Oh(g(n)) or theta (g(n)).

When do we choose big-oh over theta ?


回答1:


Use Big Theta notation when you want to also specify a lower bound. f(n) = O(g(n)) says that f is bounded above by g, whereas f(n) = Theta(g(n)) says that f is bounded both above and below by g.

In other words, there are constants k1 and k2 such that k1 * |g(n)| <= |f(n)| <= k2 * |g(n)|



来源:https://stackoverflow.com/questions/5365724/confused-on-whether-to-express-time-complexity-with-theta-notation-or-big-oh-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!