Saturday, 7 September 2013

Time Complexity for C Program

Time Complexity for C Program

I don't know if this has been asked but consider the below program.
Can I calculate an approx. complexity for this program ? (worst/best/avg.)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int no;
while((no=rand()))
printf("Hello world!\n");
return 0;
}
In this question OP has calculated the complexity of a problem which uses
random numbers, but i don't know how to do this calculation.
In Java the random gen. would take O(1) regardless of the seed.
Would this program have a constant time complexity (as it doesn't depend
on any other factors/inputs)?

No comments:

Post a Comment