Calculate the complexity of the algorithm as follows O (n ^ 2) Would it be correct?
int Smming(int n) {
int i, j, sum = 0;
for (i=n; i>0; i=i-1 {
for (j=1; j<n; j*=2){
sum+=i+2*j;
}
}
return sum;
}
And in the code below I calculated it to be O (n^2), would it be correct?
void B (int* vet, int n)
{
int i, j, pos;
for (i=0; i<n-1; i++)
{
pos = i;
for (j=i+1; j < n; j++)
if (vet[pos] > vet[j])
pos = j;
if (pos != i) {
int tmp = vet[pos];
vet[pos]=vet[i];
vet[i] = tmp;
}
}
}