What is the Big-O time complexity of this algorithm
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
23:20 UTC
Read the original article
Hit count: 254
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