I don't know if this has been asked but consider the below program.
Doubt 1
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)?
Doubt 2
int main()
{
while(1){
//some action
}
return 0;
}
Complexity for this problem?
Does infinite loop make the problem deterministic?