Recursively split the array, find the largest element in each half, then find the largest element with which the largest element was compared. This first part requires n comparisons; the last requires O (log n). Here is an example:
1 2 5 4 9 7 8 7 5 4 1 0 1 4 2 3 2 5 9 8 5 1 4 3 5 9 5 4 9 5 9
At each step, I combine the adjacent numbers and take the larger of the two. Compared to (5, 5, 8, 7), we see that the largest of them is 8, and if we look at each number that was compared with 9 (5, 5, 8, 7), it should be second largest in the array. Since this has O (log n) levels, this will require O (log n).
Running wild
source share