Question: Consider the following Java method that calculates sum of all elements in an array: public static int sum ( int [ ] arr ) {
Consider the following Java method that calculates sum of all elements in an array:
public static int sumint arr
int total ;
for int i ; i arr.length; i
total arri;
return total;
a What is the time complexity of the sum method in terms of BigO notation? Justify your answer. mark
b Suppose the array arr has n elements. If the array contains very large numbers, what is the bestcase time complexity of the sum method? Explain briefly. mark
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
