[英]Time complexity of the method
My toString() method's time complexity is supposed to be O(Row*Col)
. 我的toString()方法的时间复杂度应该是
O(Row*Col)
。 What I can see from the code is that there are two for-loops where one of them is running through the rows and the other one is running through the cols. 从代码中可以看到,有两个for循环,其中一个循环通过行,另一个循环通过cols。
Does the declaration of String variables take a lot of time? 声明String变量会花费很多时间吗? I have written code but does it have that exact time complexity?
我已经编写了代码,但是它具有确切的时间复杂度吗?
Yes, the complexity is O(Row*Col) or O(N) with N being the number of elements. 是的,复杂度为O(Row * Col)或O(N),其中N为元素数。
Declarations do not enter into the asymptotic running time, because these have constant time. 声明不会进入渐近运行时间,因为它们具有恒定的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.