223k views
5 votes
• Consider the following algorithm to calculate the sum of the n elements in an integer array a[0..n-1]. sum = 0; for (i = 0; i < n; i++) sum += a[i]; print sum; 1. What is the growth rate function for the above algorithm. (How many steps are executed when this algorithm runs?) 2. What is big O notation?

1 Answer

4 votes

Answer:

Check the explanation

Step-by-step explanation:

The loop runs for when i=0 to i=n-1 ie <n which consequently means that there are n iterations of the for loop, that is equal to array size n, therefore growth function will be

F(n) = n

Also big o notation is the upper bound of the growth function of any algorithm which consequently means that the big oh notation of this code's complexity O(n)

User Jpgooner
by
4.2k points