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