I have implemented the O(logN) + O(N)\$O(logN) + O(N)\$ version for the problem: How to find 1st and 2nd largest element in a non-negtive unique arraynon-negative unique array? The algorithm principle is from this stackoverflow answerthis stackoverflow answer.The comparison information in finding 1st helps find 2nd faster (log N\$log N\$ time).
But I am really depressed that my code is even slower than the easiest method. Theoretically, lower the numbers of comparison, smaller the cost time. I guess maybe my implementation need be optimized.
Can anyone know how to make algorithm2 faster than the easiest method?
The result: algo1 30ms, algo2 96msalgo1 30ms, algo2 96ms
.