, " ".
, , , O. wikipedia Big O:
, , , . Big O : O .
Big-O , , . , :
void linearFoo(List<String> strings){
for(String s:strings){
doSomethingWithString(s);
}
}
void quadraticFoo(List<String> strings){
for(String s:strings){
for(String s1:strings){
doSomethingWithTwoStrings(s,s1);
}
}
}
linearFoo O (n), , n (.. strings.size()). quadraticFoo O (n 2), , , quadraticFoo, strings.size().
As soon as you feel the complexity of algorithmic time, your software profiling tools will become useful. For example, you can say that if during profiling you find that the method usually takes 1 ms for a fixed input size, if this method is O (n), doubling the input size will lead to a 2 ms runtime (1ms = n, therefore 2n = 2 ms). However, if it is O (n 2 ), doubling the size of the input will mean that your method will take about 4 ms to execute (1ms = n 2 therefore (2n) 2 = 4 ms).
source
share