What is the runtime of this program

Posted by grebwerd on Programmers See other posts from Programmers or by grebwerd
Published on 2012-10-19T16:54:01Z Indexed on 2012/10/19 17:16 UTC
Read the original article Hit count: 284

Filed under:
|
|

I was wondering what the run time of this small program would be?

#include <stdio.h>

int main(int argc, char* argv[]) {

int i;
int j;
int inputSize;
int sum = 0;

if(argc == 1)
    inputSize = 16;
else
    inputSize = atoi(argv[i]);

for(i = 1; i <= inputSize; i++){
    for(j = i; j < inputSize; j *=2 ){
        printf("The value of sum is %d\n",++sum);
    }
}
}

n

S floor(log n - log (n-i)) = ?

i =1

and that each summation would be the floor value between log(n) - log(n-i).

Would the run time be n log n?

© Programmers or respective owner

Related posts about algorithms

Related posts about c