Question: Consider the following algorithm given in Java code: int ArrAverage ( int [ ] Arr ) { int n = Arr.length; int j; int k;

Consider the following algorithm given in Java code:
int ArrAverage(int [] Arr){
int n= Arr.length;
int j;
int k;
int ArrSum =0;
int Average =0;
If n =1:
Average =(array[0]+ array[1])/2
return Average
Else:
for (j =1; j < n; j*=2)
for (k =0; k < j; k=k+1)
ArrSum += array[i];
Average = ArrSum / n;
return Average;
}
(a)(10 pts) Give a big-Oh for ArrAverage, the worst-case running time of this code.Explain how you obtained this worst case.
(b)(5 pts) Give the best-case running time of this code. Explain in which scenario you obtained this best case.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!