I am new to programming and I am trying to figure out how to calculate the Big O of algorithms. For example:
int selectkth(int a[], int k, int n){
int i, j, mini, temp;
for(i=0, i < k, i++){
mini = i;
for(j = i+1; j < n; j++)
if(a[j] < a[mini])
mini = j;
temp = a[i];
a[i] = a[mini];
a[mini] = temp;
}
return a[k-1];
}
I know there are 9 steps taking place here and that the nested loops are supposed to be multiplied together. I got O(n^2) when I first attempted but I don't think that is correct. Can someone explain how to properly calculate Big O in a simplified way for a rookie like me? Any explanation will help or examples of your own. Thanks :)