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
steps

Step by step

Solved in 3 steps

Blurred answer