如何找到计算数组中和值的算法?
是这样的吗?
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 表示法。