The easiest way the figure out the running time of algorithms like this is to notice that findMax
runs over at least half of the array, for at least half of its elements (the first half).
To say the same thing in math: let T(N) be the total number of times that findMax
inner loop runs:
T(N) >= 0.5N * 0.5N
⇒ T(N) >= 0.25N²
The running time of this algorithm is therefore at least O(N²).
Then notice that findMax
runs over at most the entire array for all of its elements, and that implies that the running time is at most O(N²).