Java – complexity of code
•
Java
What is the complexity of a program with only one loop? Is it log n?
Solution
Well, it really depends on what happens in the loop
The cycle is linear time, i.e. o (n):
int sum = 0; foreach( int i in SomeCollection ) { sum += i; }
However, consider a loop that performs a substring search during each iteration Now you have to consider the complexity of string search algorithm Your question is unanswerable If you need meaningful answers, you need to provide code examples
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码