I have the Algorithm: Input: X, a 1-D numerical array of size n
Let A = an empty 1-D numerical array of size n
For i = 0 to n-1
Let s = X[0]
For j = 1 to i
Let s = s + X[j]
End For
Let A[i] = s /(i+1)
End For
Output: An n-element array A of numbers such that A[i] is the average of elements X[0],X[1], … ,X[i]
I am trying to write the T(n) formula and calculate it, how do write the for loop J = 1 to i within the for loop i = 0 to n-1.
what is the T(n) formula?
T(n) is time the algorithm takes to execute. t(n) will be used to compute the big-O ( O(n) ). so at the moment I have T(n) = 2n+2(n-1)+5i(n-1)+6(n-1)+1. as I counted the writes,reads, and operations in the algorithm. I don't know if the formula is write.