声明变量是否会计入大O记号? [英] Does declaring a variable count towards big O notation?
本文介绍了声明变量是否会计入大O记号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说在Java中我声明了一个新变量:int k = 0;这会算作O表示法吗,还是我会忽略O表示法呢?
Lets say in Java I declare a new variable: int k = 0; Will this count towards the O notation, or do I ignore it for the O notation?
推荐答案
Big O表示法会忽略常量.
Big O notation ignores the constants.
int k = 0;
是单个常量(就内存而言).
is a single constant variable(in terms of memory).
但是以下循环将具有 O(n)
复杂度
But following loop would have O(n)
complexity
for(int k=0;k<n;k++){}
它将运行 k ++
n
次.
这篇关于声明变量是否会计入大O记号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文