C++ 在时间复杂性的背景下,成本意味着什么?

C++ 在时间复杂性的背景下,成本意味着什么?,c++,time-complexity,data-science,C++,Time Complexity,Data Science,考虑以下伪代码: Pseudocode: list_Sum(A,n){//A->array and n->number of elements in the array sum =0 // cost=1 no of times=1 for i=0 to n-1 // cost=2 no of times=n+1 (+1 for the end false condition) sum = sum + A[i] // cost=2 no of ti

考虑以下伪代码:

Pseudocode:
list_Sum(A,n){//A->array and n->number of elements in the array
sum =0           // cost=1  no of times=1
for i=0 to n-1     // cost=2  no of times=n+1 (+1 for the end false condition)
sum = sum + A[i]   // cost=2  no of times=n 
return sum         // cost=1  no of times=1
}  

在时间复杂性的背景下,成本意味着什么?

实际上什么都没有。理论上,这是作者虚构的建筑所需的指令数量。实际上,它没有映射到任何现有的相关架构。没有一个真正的体系结构具有这样的成本

唯一相关的部分是
乘以1
乘以n
部分,因为这适用于任何架构


还有向量化和超标量性,它很容易地将循环的成本分为15~50个因子(因此,假设为循环体的0.02),但即使它保持代码>N次/代码>。< /p>为什么这是标记的C++?1。不同的优化将以相应的不同汇编语言结束,并且过程将与代码中的步骤不同。2.每个过程花费的时间不同。算法步骤非常快,获取数据a[i]需要花费更多的日志时间。唯一实用的方法是计算总执行时间。