Finding the maximum of an array    give a big -Oh characterization , in terms of n ,of the running time of arrayMax Method .

icon
Related questions
Question
Finding the maximum of an array 
 
give a big -Oh characterization , in terms of n ,of the running time of arrayMax Method .
 
 
1
/** Returns the maximum value of a nonempty array of numbers. */
2 public static double arrayMax(double[ ] data) {
3
int n = data.length;
4
double current Max = data[0];
for (int j=1; j<n; j++)
5
6
7
if (data[j]> current Max)
current Max = data[j];
return current Max;
8
9 }
// assume first entry is biggest (for now)
// consider all other entries
// if data[j] is biggest thus far...
// record it as the current max
Transcribed Image Text:1 /** Returns the maximum value of a nonempty array of numbers. */ 2 public static double arrayMax(double[ ] data) { 3 int n = data.length; 4 double current Max = data[0]; for (int j=1; j<n; j++) 5 6 7 if (data[j]> current Max) current Max = data[j]; return current Max; 8 9 } // assume first entry is biggest (for now) // consider all other entries // if data[j] is biggest thus far... // record it as the current max
Expert Solution
Step 1: Step 1

The array Max method, which is provided, iterates through an array of numbers to get the largest value therein. Let us examine the algorithm's time complexity in relation to the size of the input array n.


steps

Step by step

Solved in 3 steps

Blurred answer