![](/img/trans.png)
[英]determine the cost and time for every line of the code and calculate time complexity
[英]what is the unit cost of arithmetic operators (calculate the model running time)
單位成本是語句的執行時間,例如int i = 0
,由於初始化需要1
單位時間。 如果第i++
次迭代,則單位成本為1
b / c,其增量值為1
注意前后增量取1
單位時間b / c,在i所指的位置該值加1
,我們不是在假設i =100;
不同位置處加值i =100;
i++
它的作用是,只需增加位置100的值(我已經指出),因此需要增加分配成本
sum+=A[i]
花費了3
單位成本,我們將評估sum =sum+A[i] 1
延長了sum =sum+A[i] 1
單位時間,以提取A[i] 1
值, A[i] 1
+
單位為1
,最終分配的單位為1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.