我有以下算法,運行時複雜度爲O(N^2),但我希望對其有更深入的瞭解,而不是僅記住常見運行時。大O:如何確定for循環增量基於outer for循環的運行時?
什麼是正確的方法來分解它,並分析它與i+1
在考慮到內部的for循環?
void printunorderedPairs(int[] array) {
for(int i=0; i<array.length; i++) {
for(int j=i+1; j<array.length; j++) {
System.out.println(array[i] + "," + array[j]);
}
}
}
編輯
問計如何分析一個具體的問題
可能重複[大O,你如何計算/近似它?](http://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it) –