Big O

T(n) is O(f (n)), read as “T(n) is order f (n)”.

Given another function f (n), we say that T(n) is O(f (n)) (read as “T(n) is order f (n)”) if, for sufficiently large n, the function T(n) is bounded above by a constant multiple of f (n). We will also sometimes write this as T(n) = O(f (n)). More precisely, T(n) is O(f (n)) if there exist constants c > 0 and n0 ≥ 0 so that for all n ≥ n0, we have T(n) ≤ c · f (n). In this case, we will say that T is asymptotically upperbounded by f . It is important to note that this definition requires a constant c to exist that works for all n; in particular, c cannot depend on n.

Using O(·) notation, it’s easy to formally define polynomial time: a polynomial-time algorithm is one whose running time T(n) is O(nd) for some constant d, where d is independent of the input size.
We will see many algorithms whose running times have the form O(n log n). Such algorithms are also polynomial time: as we will see next, log n ≤ n for all n ≥ 1, and hence n log n ≤ n2 for all n ≥ 1. In other words, if an algorithm has running time
O(n log n), then it also has running time O(n2), and so it is a polynomial-time
algorithm.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 11,169评论 0 23
  • 其实每一天都值得我们好好过,每一天都可以快乐
    眠花城阅读 214评论 0 3
  • 加入无戒训练营第十六天,无戒批评了我们。从第一周的六十个人里有三十个人完成日更,每天写千字文,到现在每天交作业的五...
    顾子木阅读 704评论 10 12
  • 我不知道自己为什么就是不长记性,我不知道自己到底什么时候能长记性?我曾发誓不要再习惯任何人,任何事,可是现在我却没...
    rainll阅读 516评论 0 0
  • 我的学生生涯,一向温和平静而又克制,却因为一个周一深,就全然毫无章法与规矩了。 撇开那些冠冕堂皇的理由,我去这个班...
    恋爱绝缘体阅读 473评论 3 5

友情链接更多精彩内容