ACTIVITY 2:
# A is the array and n is the array size
def sum(A,n):
total =0
for i in range(n):
total = total + A [ i ]
return total
1. How many times did the operation execute?
Answer: n times
2. What is the final time complexity of the given algorithm?
Answer: O(n)
3. What is the final space complexity of the given algorithm?
Answer: O(n)
1) The operation has been executed n times.
2) Time Complexity O(n) because it has been executed n times.
3) Space Complexity O(n) because it has been executed n times.
Comments
Leave a comment