簡體   English   中英

我試圖找到以下算法的復雜性:

[英]I'm trying to find the complexity of the following algorithm:

我試圖找到以下算法的復雜性:

count = 1
j=0
for i = 1 to 100 do
        count += i
for k = 1 to n do
        count *= k
while j < n do
        count +=j
        j *= 2;
end while

對於第一個 for 循環時間復雜度是常數O(100) 第二個 for 循環的時間復雜度為O(n) while 循環也有O(n) 的時間復雜度。 所以總時間復雜度是O(100+n+n) = O(n)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM