算法时间复杂度分析 学习笔记

关于我的 Leetcode 题目解答,代码前往 Github:https://github.com/chenxiangcyr/leetcode-answers


Big-O analysis 大O符号

The Big-O Asymptotic Notation gives us the Upper Bound上界 Idea, mathematically described below:

f(n) = O(g(n)) if there exists a positive integer n0 and a positive constant c, such that f(n)≤c.g(n) ∀ n≥n0

The general step wise procedure for Big-O runtime analysis is as follows
基本步骤:

  • Figure out what the input is and what n represents. 分析输入和n
  • Express the maximum number of operations, the algorithm performs in terms of n. 最大的操作次数
  • Eliminate all excluding the highest order terms. 保留高阶,去除其他的
  • Remove all the constant factors. 去除常量

The algorithms can be classified as follows from the best-to-worst performance (Running Time Complexity)
从好到坏排序:

  • Constant Running Time – O(1)
  • A logarithmic algorithm – O(logn)
  • A linear algorithm – O(n)
  • A superlinear algorithm – O(nlogn)
  • A polynomial algorithm – O(nc)
  • A exponential algorithm – O(cn)
  • A factorial algorithm – O(n!)
不同时间复杂度的比较

渐近下限与渐近紧约束:

  • f(n) = O(g(n)) 可以理解为渐近上限
  • 渐近下限:如果g(n) = O(f(n)),则f(n) = Ω(g(n))
  • 渐近紧约束:如果f(n) = O(g(n))且f(n) = Ω(g(n)),则f(n) = Θ(g(n))

非递归算法分析

非递归算法分析

递归算法分析

迭代法与递归树
主方法

引用:
Analysis of Algorithms | Big-O analysis
算法导论------递归算法的时间复杂度求解

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

相关阅读更多精彩内容

友情链接更多精彩内容