what is big O notation?
The way that describe the relationship between the runing time and the size of problem.
1- Method of calculating time complexity of algorithm.
1)hypothesis(假设法)
class solution{
int i = 0;
while(i <= n){
i = i * 2;
}
}
assuming that the executing time is t
t = 1, i = 2
t = 2, i = 4
t = n, i = 2^t
when 2 ^ t > n then the loop is stopped.
so ㏒n = t
t = logn
大O记法是一种描述算法运行时间与问题规模之间关系的方法。它包括常数时间O(1),对数时间O(log(n)),线性时间O(n),线性对数时间O(nlog(n)),二次时间O(n^2),三次时间O(n^3),指数时间O(2^n)以及阶乘时间O(n!)等复杂度级别。本文通过实例解析了大O记法的计算方法及其在算法分析中的应用。
2045

被折叠的 条评论
为什么被折叠?



