【发布时间】:2009-05-24 16:44:08
【问题描述】:
如何找到计算数组总和值的算法??
是这样的吗?
Algorithm Array Sum
Input: nonnegative integer N, and array A[1],A[2],...,A[N]
Output: sum of the N integers in array A
Algorith Body:
j:=1
sum:=0
while j<N
sum := sum + a[J]
j:=j+1
end while
end Algorithm Array Sum
以及如何使用 O-Notation 将其与算法的运行时间联系起来
这是去年的考试,我需要为我的考试做修改。
问题
给出了一个包含 n 个整数值的数组 A[]
1.给出计算数组中所有值之和的算法
2.为算法的运行时间找到最简单和最好的O-notation。
【问题讨论】: