美文网首页
算法时间复杂度分析 学习笔记

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

作者: 专职跑龙套 | 来源:发表于2018-03-21 23:44 被阅读73次

关于我的 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
算法导论------递归算法的时间复杂度求解

相关文章

网友评论

      本文标题:算法时间复杂度分析 学习笔记

      本文链接:https://www.haomeiwen.com/subject/flqbqftx.html