I'm confused on how to create a function T(n) to measure computing time for a nested infinite loop. Here is the code:
x=1;
for(int i = 0;i<n-1;i++){
for(int j = 1; j<=x; j++){
cout << j << endl;
x*=2;
}
}
So the inner loop will go on forever, and I am stuck trying create the function to represent its computing time. I have written that its computing time is T(n) = [Summation i=0 until (n-2)] (2^j). 2^j represents the value of x with the current value of j from the inner loop. After discussing this with my peers, we definitely agree that the computing time is certainly not dependent on the value of n. We also could be completely over-thinking this as the loop is infinite and there is simply no way to express its computing time. Any help is greatly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…