How to calculate the efficiency of an algorithm?
The best way (The way I was taught at least) is to look for a basic operation. That's the operation that most significantly impacts the performance of an algorithm. In your case it looks like if T[j] &lt; minX then would be your basic operation as it's performed the most times, where the statements inside of the if check are only performed if the condition is true. The fact you have two for loops going from 1 to n-1 tell me that you're working with quadratic time. You're going to be doing your basic operation at minimum n^2 or n operations n times. This should tell you that your algorithm performs in O(n^2) timing.