Q:

Algorithm complexity Min and max

I have a question..I got an algorithm
procedure summation(A[1...n])
s=0
for i= 1 to n do
     j=min{max{i,A[i],n^3}
     s= s + j
return s

And I want to find the min and max output at this algorithm with the use of asymptotic notation θ. 
Any ideas on how to do that?
What I have to look on an algorithm to understand it's complexity?

A:

The best and the worst case are the same because the algorithm will run the "same way" every time no matter the input. So based on that we will calculate the time complexity of the algorithm using math:  

T(n) = 1 +  (3+2) + 1
  T(n) = 2 +  5
  T(n) = 2 + 5  1
  T(n) = 2 + 5 (n-1+1)
  T(n) = 5n + 2

This summation  (3+2) is due to the fact that inside the loop we have 5 distinct and measurable actions:
j = min{max{i,A[i]}, n^3} that counts as three actions because we have 2 comparisons and a value assignment to the variable j.
s = s + j that counts as 2 actions because we have one addition and a value assignment to the variable s.
Asymptotically: Θ(n)
How we calculate Θ(n):
We look at the result that is 5n + 2 and we take out the constants so it becomes
n. Then we choose the "biggest" variable that is n.
Other examples:  

8n^3+5n+2 -> Θ(n)=n^3
  10logn+n^4+7 -> Θ(n)=n^4

More info: http://bigocheatsheet.com/

