時間の複雑さに関する情報を読んでいますが、次の時間の複雑さがどのように達成されるか、およびこれを解決するための特定のルールまたは方法のセットがあるかどうかについて、かなり混乱していますか?
1)
Input: int n
for(int i = 0; i < n; i++){
print("Hello World, ");
}
for(int j = n; j > 0; j--){
print("Hello World");
}
- タイト:6n+5
- ビッグオー: O(n)
2)
Input: l = array of comparable items
Output: l = array of sorted items
Sort:
for(int i = 0; i < l.length; i++){
for(int j = 0; j < l.length; j++){
if(l{i} > l{j}){
} }
Swap(l{i},l{j});
}
return ls;
- 最悪の場合の複雑さ: 4n2 +3n+2 = O(n2)