Expected number of assignments to find maximum value in an array

Viewed 1099

In the following Java code:

int max = arr[0];
for (int i = 0; i < arr.length i++) {
    if (arr[i] > max) {
         max = arr[i];
    }
} 

How many times does the line max = arr[i]; run assuming that the array is unsorted.

1 Answers
Related